qwik-site/libs/markedRenderer.js
2022-08-13 17:16:25 +02:00

31 lines
788 B
JavaScript

import { highlight } from "./codeHighlighter.js"
export const markedRenderer = {
// Rendering of headings (add an anchor above all headings).
heading(text, level) {
return `
<a id="${text.replace(/\s/g, "-")}" data-orig-text="${text}" class="toc-anchor toc-anchor-h${level}"></a>
<h${level}>
${text}
</h${level}>
`
},
// Render code properly, and syntax highlight it.
code(code, lang, escaped) {
return `
<pre>
<code class="language-${lang}">${highlight(code, lang)}</code>
</pre>
`
},
table(header, body) {
return `
<table>
${header}
${body}
</table>
`
}
}