Add simple rendering of Markdown directive metadata to demo web page for easier diagnostics.

This commit is contained in:
David Anson 2024-01-02 22:39:24 -08:00
parent 7c2391b021
commit 9640be90a4
2 changed files with 18 additions and 1 deletions

View file

@ -33,6 +33,22 @@
.replace(/>/g, ">");
}
// Renders directive metadata
function handleDirective(directive) {
const content = directive.content;
delete directive.content;
if (content) {
this.tag("<blockquote>");
}
this.tag("<code>");
this.raw(this.encode(JSON.stringify(directive)));
this.tag("</code>");
this.raw(content);
if (content) {
this.tag("</blockquote>");
}
}
// Renders Markdown to HTML
function render(markdown) {
const match = /^\?renderer=([a-z-]+)$/.exec(window.location.search);
@ -55,7 +71,7 @@
const compileOptions = {
"allowDangerousHtml": true,
"htmlExtensions": [
micromarkHtml.directiveHtml(),
micromarkHtml.directiveHtml({ "*": handleDirective }),
micromarkHtml.gfmAutolinkLiteralHtml(),
micromarkHtml.gfmFootnoteHtml(),
micromarkHtml.gfmTableHtml(),