Skip to content

Commit

Permalink
refactor: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Apr 18, 2024
1 parent a481ebe commit 576e43a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/node/markdown/plugins/restoreEntities.ts
@@ -1,19 +1,11 @@
import type MarkdownIt from 'markdown-it'

export function restoreEntities(md: MarkdownIt): void {
md.core.ruler.before('text_join', 'entity', (state) => {
for (const token of state.tokens) {
if (token.type !== 'inline' || !token.children) continue

for (const child of token.children) {
if (child.type === 'text_special' && child.info === 'entity') {
child.type = 'entity'
}
}
md.core.ruler.disable('text_join')
md.renderer.rules.text_special = (tokens, idx) => {
if (tokens[idx].info === 'entity') {
return tokens[idx].markup // leave as is so Vue can handle it
}
})

md.renderer.rules.entity = (tokens, idx) => {
return tokens[idx].markup // leave as is so Vue can handle it
return md.utils.escapeHtml(tokens[idx].content)
}
}

0 comments on commit 576e43a

Please sign in to comment.