diff --git a/packages/vuepress-plugin/index.js b/packages/vuepress-plugin/index.js index 0d79628ee..c1210fbeb 100644 --- a/packages/vuepress-plugin/index.js +++ b/packages/vuepress-plugin/index.js @@ -14,10 +14,22 @@ module.exports = (options, ctx) => { chainMarkdown(config) { config.options.highlight((code, lang) => { if (!lang) { - return `
${code}
`
+ return `${escapeHtml(code)}
`
}
return h.codeToHtml(code, lang)
})
}
}
}
+
+const htmlEscapes = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": '''
+}
+
+function escapeHtml(html) {
+ return html.replace(/[&<>"']/g, chr => htmlEscapes[chr])
+}