Skip to content

Commit c9f538a

Browse files
committed
fix(stringify): ensure inline components are separated by space
1 parent 5242c08 commit c9f538a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/runtime/stringify/mdc-remark.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,24 @@ export function mdcRemark(options?: Options | undefined | null) {
6060
/**
6161
* Revert textDirective to textComponent
6262
*/
63-
visit(mdast, node => node.type === mdastTextComponentType, (node) => {
63+
visit(mdast, node => node.type === mdastTextComponentType, (node, index, parent) => {
6464
node.type = mdcTextComponentType as typeof node.type
65+
66+
// ensure :br and inline components are separated by a space
67+
if (index && parent && parent.children) {
68+
if (index > 0 && parent.children[index - 1].type === 'text') {
69+
const text = parent.children[index - 1] as Text
70+
if (!['\n', ' ', '\t'].includes(text.value.slice(-1))) {
71+
text.value += ' '
72+
}
73+
}
74+
if (index && index < parent.children.length - 1 && parent.children[index + 1].type === 'text') {
75+
const text = parent.children[index + 1] as Text
76+
if (!['\n', ' ', '\t'].includes(text.value.slice(0, 1))) {
77+
text.value = ' ' + text.value
78+
}
79+
}
80+
}
6581
})
6682

6783
return mdast

0 commit comments

Comments
 (0)