From 9f4987b6330ee84483a8659d61cd2f70f26f007b Mon Sep 17 00:00:00 2001 From: Arpita-Jaiswal Date: Thu, 5 Oct 2023 14:13:48 +0530 Subject: [PATCH] Fixing html content inside codeblock --- fastn-js/js/dom.js | 3 +++ fastn-js/js/utils.js | 14 +++++++++++++- fastn-js/{markdown.js => marked.js} | 0 fastn-js/src/lib.rs | 2 +- ftd/t/js/56-title-fix.ftd | 4 +++- 5 files changed, 20 insertions(+), 3 deletions(-) rename fastn-js/{markdown.js => marked.js} (100%) diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index 6d088243f6..dd36e1d0f3 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -1878,8 +1878,11 @@ class Node2 { } else if (kind === fastn_dom.PropertyKind.StringValue) { this.#rawInnerValue = staticValue; if (!hydrating) { + console.log("Before staticValue", staticValue); staticValue = fastn_utils.markdown_inline(fastn_utils.escapeHtmlInMarkdown(staticValue)); + console.log("After staticValue", staticValue); staticValue = fastn_utils.process_post_markdown(this.#node, staticValue); + console.log("More After staticValue", staticValue); } else { staticValue = this.#node.innerHTML; } diff --git a/fastn-js/js/utils.js b/fastn-js/js/utils.js index 3c59f817a0..15a84bb60e 100644 --- a/fastn-js/js/utils.js +++ b/fastn-js/js/utils.js @@ -255,6 +255,7 @@ let fastn_utils = { * @returns {string} - The processed string with inline markdown. */ markdown_inline(i) { + console.log("Before markdown_inline", i); if (fastn_utils.isNull(i)) return; const { space_before, space_after } = fastn_utils.private.spaces(i); const o = (() => { @@ -459,9 +460,20 @@ let fastn_utils = { "'": "'", '/': "/", }; + let foundBackTick = false; for (var i = 0; i < str.length; i++) { let current = str[i]; - if (current === '/' && !(i > 0 && str[i-1] === "<")) { + if (current === "`") { + foundBackTick = !foundBackTick; + } + // Ignore escaping html inside backtick (as marked function + // escape html for backtick content): + // For instance: In `hello `, `<` and `>` should not be + // escaped. (`foundBackTick`) + // Also the `/` which is followed by `<` should be escaped. + // For instance: `</` should be escaped but `http://` should not + // be escaped. (`(current === '/' && !(i > 0 && str[i-1] === "<"))`) + if (foundBackTick || (current === '/' && !(i > 0 && str[i-1] === "<"))) { result += current; continue; } diff --git a/fastn-js/markdown.js b/fastn-js/marked.js similarity index 100% rename from fastn-js/markdown.js rename to fastn-js/marked.js diff --git a/fastn-js/src/lib.rs b/fastn-js/src/lib.rs index d0abc46319..64f722c956 100644 --- a/fastn-js/src/lib.rs +++ b/fastn-js/src/lib.rs @@ -66,5 +66,5 @@ pub fn all_js_with_test() -> String { } pub fn markdown_js() -> &'static str { - include_str!("../markdown.js") + include_str!("../marked.js") } diff --git a/ftd/t/js/56-title-fix.ftd b/ftd/t/js/56-title-fix.ftd index 5336920e87..78907259d5 100644 --- a/ftd/t/js/56-title-fix.ftd +++ b/ftd/t/js/56-title-fix.ftd @@ -1,5 +1,7 @@ -- ftd.text: -this is a `<title>` +this is a `Hello <title>` + +<a> ppp </a> ;; Escaped Output: this is a `<title>`