qwik-site/libs/markedRenderer.js

31 lines
788 B
JavaScript
Raw Normal View History

2021-08-09 17:44:53 +02:00
import { highlight } from "./codeHighlighter.js"
export const markedRenderer = {
// Rendering of headings (add an anchor above all headings).
heading(text, level) {
return `
2022-08-13 17:16:25 +02:00
<a id="${text.replace(/\s/g, "-")}" data-orig-text="${text}" class="toc-anchor toc-anchor-h${level}"></a>
2021-08-09 17:44:53 +02:00
<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>
`
2021-08-10 22:49:20 +02:00
},
table(header, body) {
return `
<table>
${header}
${body}
</table>
`
2021-08-09 17:44:53 +02:00
}
}