Skip to content

Commit d02d1e9

Browse files
committed
fix(build/regression): markdown backslash escapes not working
closes #3808
1 parent f30b848 commit d02d1e9

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/node/markdown/markdown.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { sfcPlugin, type SfcPluginOptions } from '@mdit-vue/plugin-sfc'
1414
import { titlePlugin } from '@mdit-vue/plugin-title'
1515
import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc'
1616
import { slugify } from '@mdit-vue/shared'
17-
import MarkdownIt from 'markdown-it'
1817
import type { Options } from 'markdown-it'
18+
import MarkdownIt from 'markdown-it'
1919
import anchorPlugin from 'markdown-it-anchor'
2020
import attrsPlugin from 'markdown-it-attrs'
2121
// @ts-expect-error: types of markdown-it-emoji are not up-to-date
@@ -29,14 +29,15 @@ import type {
2929
} from 'shiki'
3030
import type { Logger } from 'vite'
3131
import { containerPlugin, type ContainerOptions } from './plugins/containers'
32+
import { gitHubAlertsPlugin } from './plugins/githubAlerts'
3233
import { highlight } from './plugins/highlight'
3334
import { highlightLinePlugin } from './plugins/highlightLines'
3435
import { imagePlugin, type Options as ImageOptions } from './plugins/image'
3536
import { lineNumberPlugin } from './plugins/lineNumbers'
3637
import { linkPlugin } from './plugins/link'
3738
import { preWrapperPlugin } from './plugins/preWrapper'
39+
import { restoreEntities } from './plugins/restoreEntities'
3840
import { snippetPlugin } from './plugins/snippet'
39-
import { gitHubAlertsPlugin } from './plugins/githubAlerts'
4041

4142
export type { Header } from '../shared'
4243

@@ -205,11 +206,7 @@ export const createMarkdownRenderer = async (
205206
})
206207

207208
md.linkify.set({ fuzzyLink: false })
208-
209-
// disable entity decode/escape from markdown-it, as the Vue compiler already
210-
// decodes them.
211-
md.disable('entity')
212-
md.renderer.rules.text = (tokens, idx) => tokens[idx].content
209+
md.use(restoreEntities)
213210

214211
if (options.preConfig) {
215212
options.preConfig(md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type MarkdownIt from 'markdown-it'
2+
3+
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+
}
13+
}
14+
})
15+
16+
md.renderer.rules.entity = (tokens, idx) => {
17+
return tokens[idx].markup // leave as is so Vue can handle it
18+
}
19+
}

0 commit comments

Comments
 (0)