feat(plugins/code): add new code plugin (#526)

This commit is contained in:
Simon Lecoq
2021-09-13 13:31:36 +02:00
committed by GitHub
parent 47a0689d4c
commit 842aee763f
11 changed files with 256 additions and 10 deletions

View File

@@ -208,16 +208,15 @@ export async function which(command) {
return false
}
/**Code hightlighter */
export async function highlight(code, lang) {
return lang in prism.languages ? prism.highlight(code, prism.languages[lang]) : code
}
/**Markdown-html sanitizer-interpreter */
export async function markdown(text, {mode = "inline", codelines = Infinity} = {}) {
//Sanitize user input once to prevent injections and parse into markdown
let rendered = await marked(htmlunescape(htmlsanitize(text)), {
highlight(code, lang) {
return lang in prism.languages ? prism.highlight(code, prism.languages[lang]) : code
},
silent:true,
xhtml:true,
})
let rendered = await marked(htmlunescape(htmlsanitize(text)), {highlight, silent:true, xhtml:true})
//Markdown mode
switch (mode) {
case "inline": {