Skip to content

Commit 576e43a

Browse files
committed
refactor: simplify code
1 parent a481ebe commit 576e43a

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Diff for: src/node/markdown/plugins/restoreEntities.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import type MarkdownIt from 'markdown-it'
22

33
export function restoreEntities(md: MarkdownIt): void {
4-
md.core.ruler.before('text_join', 'entity', (state) => {
5-
for (const token of state.tokens) {
6-
if (token.type !== 'inline' || !token.children) continue
7-
8-
for (const child of token.children) {
9-
if (child.type === 'text_special' && child.info === 'entity') {
10-
child.type = 'entity'
11-
}
12-
}
4+
md.core.ruler.disable('text_join')
5+
md.renderer.rules.text_special = (tokens, idx) => {
6+
if (tokens[idx].info === 'entity') {
7+
return tokens[idx].markup // leave as is so Vue can handle it
138
}
14-
})
15-
16-
md.renderer.rules.entity = (tokens, idx) => {
17-
return tokens[idx].markup // leave as is so Vue can handle it
9+
return md.utils.escapeHtml(tokens[idx].content)
1810
}
1911
}

0 commit comments

Comments
 (0)