From a1dc72ba6629b3ca4304ea52f71e1ef4e6d61cd8 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Wed, 26 Nov 2025 03:45:34 +0530 Subject: [PATCH] SimpleChatTCRV:MarkDown:Cleanup overall initial go Save copy of data being processed. Try and sanitize the data passed for markdown to html conversion, so that if there are any special characters wrt html in the passed markdown content, it gets translated into a harmless text. This also ensures that those text dont disappear, bcas of browser trying to interpret them as html tagged content. Trap any errors during sanitizing and or processing of the lines in general and push them into a errors array. Callers of this markdown class can decide whether to use the converted html or not based on errors being empty or not or ... Move the processing of unordered list into a function of its own. Rather the ordered list can also use the same flow in general except for some tiny changes including wrt the regex, potentially. --- tools/server/public_simplechat/typemd.mjs | 91 ++++++++++++++--------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index 100ff04519..3d2f90f0ca 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -25,7 +25,11 @@ export class MarkDown { /** @type {Array} */ listUnordered: [] } - this.md = "" + /** + * @type {Array<*>} + */ + this.errors = [] + this.raw = "" this.html = "" } @@ -40,6 +44,48 @@ export class MarkDown { this.unwind_list_unordered() } + /** + * Process a unordered list one line at a time + * @param {string} line + */ + process_list_unordered(line) { + // spaces followed by - or + or * followed by a space and actual list item + let matchUnOrdered = line.match(/^([ ]*)[-+*][ ](.*)$/); + if (matchUnOrdered != null) { + let sList = 'none' + let listLvl = 0 + if (this.in.listUnordered.length == 0) { + sList = 'same' + this.in.listUnordered.push(matchUnOrdered[1].length) + listLvl = this.in.listUnordered.length // ie 1 + this.html += "