From cfe4ff8d56e7a8843da25b35c6bf9deaffbbcdd7 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 28 Feb 2022 07:54:55 +1000 Subject: [PATCH] FIX: Make sure html_raw is hoisted in custom markdown cook function (#16050) When returning the customRenderFn from within buildCustomMarkdownCookFunction for custom markdown engines (such as the one used by the [chat] transcripts) we were not hoisting/unhoisting the `html_raw` tokens created by the transcript, which meant that opts.discourse.hoisted could end up in a state where it was null, and which caused errors and general unpleasantness. Instead, we can just call the `cook` function that is already exported from discourse-markdown-it, that takes care of what we did previously plus the hoisting. There is a companion chat commit that adds tests for this, there are no custom markdown engine usages in core to test with. --- .../pretty-text/addon/engines/discourse-markdown-it.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js b/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js index 558f66cdf0d..b9c9f4759a9 100644 --- a/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js +++ b/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js @@ -337,9 +337,7 @@ function buildCustomMarkdownCookFunction(engineOpts, defaultEngineOpts) { // we don't need the whole engine as a consumer, just a cook function // will do return function customRenderFn(contentToRender) { - return newOpts.discourse - .sanitizer(newOpts.engine.render(contentToRender)) - .trim(); + return cook(contentToRender, newOpts); }; }