Skip to content

Commit

Permalink
Fixing html content inside codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Oct 5, 2023
1 parent 1904b4e commit 9f4987b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions fastn-js/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion fastn-js/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (() => {
Expand Down Expand Up @@ -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 <title>`, `<` 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;
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion fastn-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 3 additions & 1 deletion ftd/t/js/56-title-fix.ftd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- ftd.text:

this is a `<title>`
this is a `Hello <title>`

<a> ppp </a>

;; Escaped Output: this is a `&lt;title&gt;`

0 comments on commit 9f4987b

Please sign in to comment.