2021-08-07 10:46:48 +02:00
|
|
|
import { highlight } from "./codeHighlighter.js"
|
2021-08-07 10:16:13 +02:00
|
|
|
|
2021-08-06 14:46:16 +02:00
|
|
|
export const markedRenderer = {
|
2021-08-07 10:46:48 +02:00
|
|
|
// Rendering of headings (add an anchor above all headings).
|
2021-08-05 23:27:11 +02:00
|
|
|
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>
|
|
|
|
`
|
|
|
|
}
|
2021-08-05 23:27:11 +02:00
|
|
|
}
|