From 9b75e494be545d18428d90821938afe19878e3a5 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Wed, 26 Nov 2025 12:10:54 +0530 Subject: [PATCH] SimpleChatTCRV:Markdown:OrderedUnOrderd: Simplify flow Avoid seperate new list level logic for a fresh list and list with in list paths. Rather adjust lastOffset specifically for fresh list. All paths lead to need to insert list item and the difference to be handled wrt starting or ending a list level is handled by respective condition check blocks directly without delaying it for later so no need for that sList state, so remove. Avoid check for same level list item path, as nothing special needs to be do in that path currently. Live identify the last offset, when unwinding. NOTE: Logic currently will handle ordered lists on their own or unordered lists on thier own or intermixed list containing both type of lists within them, however remember that all will be shown as unordered lists. ALERT: if there is a really long line, the logic currently doesnt support it being broken into smaller line with same or greater offset than the line identifying the current list item. --- tools/server/public_simplechat/typemd.mjs | 39 +++++++++-------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index a7f6017568..05ba522ff9 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -54,37 +54,28 @@ export class MarkDown { // spaces followed by - or + or * followed by a space and actual list item let matchUnOrdered = line.match(/^([ ]*)([-+*]|[a-zA-Z0-9]\.)[ ](.*)$/); if (matchUnOrdered != null) { - let sList = 'none' let listLvl = 0 let curOffset = matchUnOrdered[1].length - if (this.in.list.offsets.length == 0) { - sList = 'same' + let lastOffset = this.in.list.offsets[this.in.list.offsets.length-1]; + if (lastOffset == undefined) { + lastOffset = -1 + } + + if (lastOffset < curOffset){ this.in.list.offsets.push(curOffset) - listLvl = this.in.list.offsets.length // ie 1 + listLvl = this.in.list.offsets.length this.html += "\n` + if (this.in.list.offsets.length == 0) { + break } } } - if (sList == 'same') { - this.html += `
  • ${matchUnOrdered[3]}
  • \n` - } + + this.html += `
  • ${matchUnOrdered[3]}
  • \n` return true } return false