From 31c034c02918aafb36608296708343dc0bcb4d92 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 19 Nov 2025 23:53:39 -0500 Subject: [PATCH] Rework Marked custom HTML renderer to skip preprocess step Marked Variables are getting cleared when the custom HTML renderer runs, because Marked.parse re-runs the whole pipeline, including the preprocessor. Preprocess should only be run once globally during the pipeline, or the original results get overwritten (Marked Variables clears its global array of variables each time it is run) --- shared/markdown.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shared/markdown.js b/shared/markdown.js index 412be27a7..eecc945f9 100644 --- a/shared/markdown.js +++ b/shared/markdown.js @@ -31,7 +31,12 @@ renderer.html = function (token) { const openTag = html.substring(0, html.indexOf('>')+1); html = html.substring(html.indexOf('>')+1); html = html.substring(0, html.lastIndexOf('')); - return `${openTag} ${Marked.parse(html)} `; + + // Repeat the markdown processing for content inside the div, minus the preprocessing and postprocessing hooks which should only run once globally + const opts = Marked.defaults; + const tokens = Marked.lexer(html, opts); + Marked.walkTokens(tokens, opts.walkTokens); + return `${openTag} ${Marked.parser(tokens, opts)} `; } return html; };