From 4fdba6e131cba98802c0323e45a1d2d6c9dcc34c Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 18 Apr 2024 22:19:22 +0530 Subject: [PATCH] refactor: simplify code --- src/node/markdown/plugins/restoreEntities.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/node/markdown/plugins/restoreEntities.ts b/src/node/markdown/plugins/restoreEntities.ts index d15bc5225693..768fe8804b96 100644 --- a/src/node/markdown/plugins/restoreEntities.ts +++ b/src/node/markdown/plugins/restoreEntities.ts @@ -1,19 +1,15 @@ 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 + md.core.ruler.disable('text_join') - for (const child of token.children) { - if (child.type === 'text_special' && child.info === 'entity') { - child.type = 'entity' - } - } - } - }) + const defaultTextRenderer = md.renderer.rules.text! - md.renderer.rules.entity = (tokens, idx) => { - return tokens[idx].markup // leave as is so Vue can handle it + md.renderer.rules.text_special = (...args) => { + const [tokens, idx] = args + if (tokens[idx].info === 'entity') { + return tokens[idx].markup // leave as is so Vue can handle it + } + return defaultTextRenderer(...args) } }