syntax highlighting

This commit is contained in:
2026-06-01 15:20:30 +01:00
parent 9aff454ec2
commit 63ca617895
3 changed files with 24 additions and 2 deletions
+16
View File
@@ -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)
};