diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index 4ba6f029d9..26c0182a3c 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -242,6 +242,32 @@ export class MarkDown { } } + /** + * Process Pre Fenced block one line at a time. + * @param {string} line + */ + process_pre_fenced(line) { + if (this.in.preFenced.length > 0) { + if (line == this.in.preFenced) { + this.in.preFenced = "" + this.html += "\n" + } else { + this.html += `${line}\n` + } + return true + } + // same number of space followed by ``` or ~~~ + // some samples with spaces at beginning seen, so accepting spaces at begin + let matchPreFenced = line.match(/^(\s*```|\s*~~~)([a-zA-Z0-9]*)(.*)/); + if ( matchPreFenced != null) { + this.unwind_list() + this.in.preFenced = matchPreFenced[1] + this.html += `
\n`
+            return true
+        }
+        return false
+    }
+
     unwind_blockquote() {
         for(let i=0; i\n`
@@ -287,13 +313,7 @@ export class MarkDown {
             line = elSanitize.innerHTML
         }
         let lineA = line.split(' ')
-        if (this.in.preFenced.length > 0) {
-            if (line == this.in.preFenced) {
-                this.in.preFenced = ""
-                this.html += "
\n" - } else { - this.html += `${line}\n` - } + if (this.process_pre_fenced(line)) { return } if (this.process_table_line(line)) { @@ -312,15 +332,6 @@ export class MarkDown { this.html += `${line.slice(hLevel)}\n` return } - // same number of space followed by ``` or ~~~ - // some samples with spaces at beginning seen, so accepting spaces at begin - let matchPreFenced = line.match(/^(\s*```|\s*~~~)([a-zA-Z0-9]*)(.*)/); - if ( matchPreFenced != null) { - this.unwind_list() - this.in.preFenced = matchPreFenced[1] - this.html += `
\n`
-            return
-        }
         if (this.process_blockquote(line, lineA[0])) {
             return
         }