qwik-cms/libs/markedRenderer.js

22 lines
638 B
JavaScript
Raw Normal View History

2021-08-07 10:46:48 +02:00
import { highlight } from "./codeHighlighter.js"
2021-08-07 10:16:13 +02:00
export const markedRenderer = {
2021-08-07 10:46:48 +02:00
// Rendering of headings (add an anchor above all headings).
heading(text, level) {
return `
<a name="${text.replace(/\s/g, "-")}" data-orig-text="${text}" class="toc-anchor toc-anchor-h${level}"></a>
<h${level}>
${text}
</h${level}>
`
2021-08-07 10:16:13 +02:00
},
2021-08-07 10:46:48 +02:00
// Render code properly, and syntax highlight it.
2021-08-07 10:16:13 +02:00
code(code, lang, escaped) {
return `
<pre>
<code class="language-${lang}">${highlight(code, lang)}</code>
</pre>
`
}
}