Skip to content

Commit

Permalink
Merge pull request #93 from yzhang-gh/patch-1
Browse files Browse the repository at this point in the history
Fix #63 for vuepress plugin
  • Loading branch information
octref committed Sep 22, 2020
2 parents 586b741 + 6a4f696 commit 8b247a1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/vuepress-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ module.exports = (options, ctx) => {
chainMarkdown(config) {
config.options.highlight((code, lang) => {
if (!lang) {
return `<pre><code>${code}</code></pre>`
return `<pre><code>${escapeHtml(code)}</code></pre>`
}
return h.codeToHtml(code, lang)
})
}
}
}

const htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
}

function escapeHtml(html) {
return html.replace(/[&<>"']/g, chr => htmlEscapes[chr])
}

0 comments on commit 8b247a1

Please sign in to comment.