syntax highlighting
This commit is contained in:
@@ -127,6 +127,8 @@ export function render_comment(comment_content)
|
||||
export function render_md(content)
|
||||
{
|
||||
const markdownit = require("markdown-it")
|
||||
const hljs = require("highlight.js");
|
||||
const namedCodeBlocks = require("markdown-it-named-code-blocks");
|
||||
const md = markdownit
|
||||
({ // this is just defining some options for markdown-it, should I add this to config.json?
|
||||
html: false,
|
||||
@@ -135,7 +137,21 @@ export function render_md(content)
|
||||
linkify: false,
|
||||
typographer: true,
|
||||
quotes: locale.quotes,
|
||||
highlight: function (content, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
return (
|
||||
'<pre class="hljs"><code>' +
|
||||
hljs.highlight(content, { language: lang, ignoreIllegals: true }).value +
|
||||
"</code></pre>"
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
'<pre class="hljs"><code>' + md.utils.escapeHtml(content) + "</code></pre>"
|
||||
);
|
||||
}
|
||||
})
|
||||
.use(namedCodeBlocks)
|
||||
.disable('image');
|
||||
return md.render(content)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user