From d89e92185a4e2d8eb1a93115d51e5aec78f4e51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Tue, 4 Jun 2024 15:48:41 +0700 Subject: [PATCH] Do not duplicate
tags inside Mermaid graphs --- assets/js/lib/markdown.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assets/js/lib/markdown.js b/assets/js/lib/markdown.js index 11fa243ab..4793721db 100644 --- a/assets/js/lib/markdown.js +++ b/assets/js/lib/markdown.js @@ -83,7 +83,14 @@ class Markdown { .use(rehypeKatex) .use(rehypeMermaid) .use(rehypeExternalLinks, { baseUrl: this.baseUrl }) - .use(rehypeStringify) + .use(rehypeStringify, { + // Mermaid allows HTML tags, such as
in diagram labels. + // We parse the SVG earlier, then stringify it, closeEmptyElements + // makes sure we emit
as a self-closing tag, rather than + //

(which the browser would interpret as two breaks). + // See https://github.com/syntax-tree/hast-util-to-html/blob/9d7a2f7d63ec2d11b3ae5a5e4201181fdeedf6ea/lib/handle/element.js#L66-L69 + closeEmptyElements: true, + }) .process(this.content) .then((file) => String(file)) .catch((error) => {