From bf7f72b74bfe8f1706ec764a5fa783b8cc8017c1 Mon Sep 17 00:00:00 2001 From: Harsh Singh <64768386+harshdoesdev@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:35:25 +0530 Subject: [PATCH] prevent undefined from getting printed in markdown text (#1379) * prevents undefined from getting printed in markdown * fix all tests --- fastn-js/js/dom.js | 4 +++- ftd/t/js/21-markdown.ftd | 13 +++++++++++++ ftd/t/js/21-markdown.html | 19 ++++++++++++++++++- ftd/t/js/63-external-js.html | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index c5b96f41ff..3a772debf4 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -1883,7 +1883,9 @@ class Node2 { staticValue = this.#node.innerHTML; } staticValue = fastn_utils.process_post_markdown(this.#node, staticValue); - this.#node.innerHTML = staticValue; + if(!fastn_utils.isNull(staticValue)) { + this.#node.innerHTML = staticValue; + } } else { throw ("invalid fastn_dom.PropertyKind: " + kind); } diff --git a/ftd/t/js/21-markdown.ftd b/ftd/t/js/21-markdown.ftd index 2c33876191..ae5e34ab01 100644 --- a/ftd/t/js/21-markdown.ftd +++ b/ftd/t/js/21-markdown.ftd @@ -3,3 +3,16 @@ # Marked in the browser Rendered by **marked**. + +-- component markdown: +body string text: + +-- ftd.text: +text: $markdown.text + +-- end: markdown + +-- markdown: + +;; COMMENT NEXT LINE +;; Go to the [new page](/new-page/). diff --git a/ftd/t/js/21-markdown.html b/ftd/t/js/21-markdown.html index 65d4513368..a5aaf0d950 100644 --- a/ftd/t/js/21-markdown.html +++ b/ftd/t/js/21-markdown.html @@ -17,7 +17,7 @@

Marked in the browser

-Rendered by marked.
@@ -31,11 +31,28 @@ try { let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Text); parenti0.setProperty(fastn_dom.PropertyKind.StringValue, "# Marked in the browser\n\nRendered by **marked**.", inherited); + let parenti1 = foo__markdown(parent, inherited); } finally { __fastn_package_name__ = __fastn_super_package_name__; } } global["main"] = main; +let foo__markdown = function (parent, inherited, args) { + let __fastn_super_package_name__ = __fastn_package_name__; + __fastn_package_name__ = "foo"; + try { + let __args__ = { + }; + inherited = fastn_utils.getInheritedValues(__args__, inherited, args); + __args__ = fastn_utils.getArgs(__args__, args); + let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Text); + parenti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.text, inherited); + return parenti0; + } finally { + __fastn_package_name__ = __fastn_super_package_name__; + } +} +global["foo__markdown"] = foo__markdown; fastn_dom.codeData.availableThemes["coldark-theme.dark"] = "../../theme_css/coldark-theme.dark.css"; fastn_dom.codeData.availableThemes["coldark-theme.light"] = "../../theme_css/coldark-theme.light.css"; fastn_dom.codeData.availableThemes["coy-theme"] = "../../theme_css/coy-theme.css"; diff --git a/ftd/t/js/63-external-js.html b/ftd/t/js/63-external-js.html index 7d5746bd37..3ac3b66348 100644 --- a/ftd/t/js/63-external-js.html +++ b/ftd/t/js/63-external-js.html @@ -16,7 +16,7 @@ -
Hello
undefined