Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/composable-vue/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ watch(counter, count => {
```html
<template>
<button @click="counter += 1">
Counter is {\{ counter }}
Counter is {{ counter }}
</button>
</template>
```
Expand Down
8 changes: 0 additions & 8 deletions packages/slidev/node/plugins/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,5 @@ export function createFixPlugins(
return code.replace(/__DEV__/g, DEV)
},
},
{
name: 'slidev:vue-escape-post',
enforce: 'post',
transform(code, id) {
if (id.endsWith('.md'))
return code.replace(/\\{/g, '{')
},
},
]
}
3 changes: 1 addition & 2 deletions packages/slidev/node/plugins/markdown-it-prism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function selectLanguage(options: Options, lang: string): [string, Grammar | unde
* (markdown-it’s langPrefix + lang). If Prism knows {@code lang}, {@code text} will be highlighted by it.
*/
function highlight(markdownit: MarkdownIt, options: Options, text: string, lang: string): string {
text = escapeVueInCode(text)
const [langToUse, prismLang] = selectLanguage(options, lang)
const code = text
.trimEnd()
Expand All @@ -120,7 +119,7 @@ function highlight(markdownit: MarkdownIt, options: Options, text: string, lang:
const classAttribute = langToUse
? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"`
: ''
return `<pre${classAttribute}><code>${code}</code></pre>`
return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`)
}

/**
Expand Down
6 changes: 2 additions & 4 deletions packages/slidev/node/plugins/markdown-it-shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ const MarkdownItShiki: MarkdownIt.PluginWithOptions<ShikiOptions> = (markdownit,
const { darkModeThemes } = resolveShikiOptions(options!)

markdownit.options.highlight = (code, lang) => {
code = escapeVueInCode(code)
if (darkModeThemes) {
const dark = _highlighter
.codeToHtml(code, lang || 'text', darkModeThemes.dark)
.replace('<pre class="shiki"', '<pre class="slidev-code shiki shiki-dark"')
const light = _highlighter
.codeToHtml(code, lang || 'text', darkModeThemes.light)
.replace('<pre class="shiki"', '<pre class="slidev-code shiki shiki-light"')
return `<pre class="shiki-container">${dark}${light}</pre>`
return escapeVueInCode(`<pre class="shiki-container">${dark}${light}</pre>`)
}
else {
return _highlighter.codeToHtml(code, lang || 'text')
.replace('<pre class="shiki"', '<pre class="slidev-code shiki"')
return escapeVueInCode(_highlighter.codeToHtml(code, lang || 'text').replace('<pre class="shiki"', '<pre class="slidev-code shiki"'))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/slidev/node/plugins/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ export function transformMermaid(md: string): string {
}

export function escapeVueInCode(md: string) {
return md.replace(/{({.*}})/g, '{\\$1')
return md.replace(/{{(.*)}}/g, '&lbrace;&lbrace;$1&rbrace;&rbrace;')
}