From 95c8cd6eba74881b8bada89c6bcbe9d6080ab4a3 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Tue, 25 Nov 2025 23:24:37 +0530 Subject: [PATCH] SimpleChatTCRV:MarkDown: Better Fenced Pre Allow fenced code block / pre to be demarkated using either ``` or ~~~ Ensure the termination line wrt fenced block doesnt contain anything else. Same starting marker needs to be present wrt ending also --- tools/server/public_simplechat/typemd.mjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index 458dbc34ae..71aed12775 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -8,7 +8,7 @@ export class MarkDown { constructor() { this.in = { - pre: false, + preFenced: "", table: false, /** @type {Array} */ listUnordered: [] @@ -34,9 +34,9 @@ export class MarkDown { */ process_line(line) { let lineA = line.split(' ') - if (this.in.pre) { - if (lineA[0] == '```') { - this.in.pre = false + if (this.in.preFenced.length > 0) { + if (line == this.in.preFenced) { + this.in.preFenced = "" this.html += "\n" } else { this.html += `${line}\n` @@ -54,11 +54,11 @@ export class MarkDown { this.html += `${line.slice(hLevel)}\n` return } - let matchPre = line.match(/^```([a-zA-Z0-9]*)(.*)/); - if ( matchPre != null) { + let matchPreFenced = line.match(/^(```|~~~)([a-zA-Z0-9]*)(.*)/); + if ( matchPreFenced != null) { this.unwind_list() - this.in.pre = true - this.html += `
\n`
+            this.in.preFenced = matchPreFenced[1]
+            this.html += `
\n`
             return
         }
         let matchUnOrdered = line.match(/^([ ]*)[-+*][ ](.*)$/);