Skip to content

Commit b07a087

Browse files
authored
fix: fix <br/> and space in strong temporarily (#17)
1 parent 47048dc commit b07a087

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

.changeset/curvy-eggs-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cf2md": patch
3+
---
4+
5+
fix: fix <br/> and space in strong temporarily

src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Element } from 'hast'
1+
import type { Content, Element } from 'hast'
22
import { isElement } from 'hast-util-is-element'
33
import type { Paragraph, Strong, Text } from 'mdast'
44
import type { BlockContent, ContainerDirective } from 'mdast-util-directive'
@@ -20,6 +20,9 @@ const processor = unified()
2020
.use(remarkGfm)
2121
.use(rehypeRemark, {
2222
handlers: {
23+
br(h, node: Content) {
24+
return h(node, 'html', '<br>')
25+
},
2326
div(h, node: Element) {
2427
const classList = getClassList(node)
2528

@@ -123,6 +126,15 @@ const processor = unified()
123126
}
124127
: codeNode
125128
},
129+
strong(h, node: Element) {
130+
const strongNode = defaultHandlers.strong(h, node) as Strong
131+
for (const child of strongNode.children) {
132+
if (child.type === 'text') {
133+
child.value = child.value.trim()
134+
}
135+
}
136+
return strongNode
137+
},
126138
},
127139
})
128140
.use(remarkStringify, {

test/__snapshots__/fixtures.spec.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ cp /etc/kubernetes/manifests/kube-apiserver.yaml ./kube-apiserver.yaml_backup
7373
7474
经验是……
7575
76+
1. 参考以下说明,配置关键参数。
77+
78+
<br>
79+
80+
* **添加告警规则**,并设置 **告警规则**相关参数:
81+
82+
<br>
83+
84+
* **告警类型** 选择 **自定义告警。**
85+
7686
\\\\-end-
7787
"
7888
`;

test/fixtures/basic.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,20 @@ <h3 id="早睡"><a href="#早睡">早睡</a></h3>
232232
</style>
233233
<p><br /></p>
234234
<p><br /></p>
235+
236+
<ol>
237+
<li>
238+
参考以下说明,配置关键参数。<br />
239+
<ul>
240+
<li>
241+
<strong>添加告警规则</strong>,并设置
242+
<strong>告警规则&nbsp;</strong>相关参数:<br />
243+
<ul>
244+
<li><strong>告警类型</strong> 选择 <strong>自定义告警。</strong></li>
245+
</ul>
246+
</li>
247+
</ul>
248+
</li>
249+
</ol>
250+
235251
<p>-end-</p>

test/fixtures/basic.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ cp /etc/kubernetes/manifests/kube-apiserver.yaml ./kube-apiserver.yaml_backup
7070

7171
经验是……
7272

73+
1. 参考以下说明,配置关键参数。
74+
75+
<br>
76+
77+
* **添加告警规则**,并设置 **告警规则**相关参数:
78+
79+
<br>
80+
81+
* **告警类型** 选择 **自定义告警。**
82+
7383
\-end-

0 commit comments

Comments
 (0)