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.
This commit is contained in:
hanishkvc 2025-11-26 12:10:54 +05:30
parent e7b8fc1392
commit 9b75e494be
1 changed files with 15 additions and 24 deletions

View File

@ -54,26 +54,19 @@ 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'
this.in.list.offsets.push(curOffset)
listLvl = this.in.list.offsets.length // ie 1
this.html += "<ul>\n"
} else {
let lastOffset = this.in.list.offsets[this.in.list.offsets.length-1];
if (lastOffset == undefined) {
lastOffset = -1
}
if (lastOffset < curOffset){
sList = 'same'
this.in.list.offsets.push(curOffset)
listLvl = this.in.list.offsets.length
this.html += "<ul>\n"
} else if (lastOffset == curOffset){
sList = 'same'
} else {
sList = 'same'
while (lastOffset > curOffset) {
} else if (lastOffset > curOffset){
while (this.in.list.offsets[this.in.list.offsets.length-1] > curOffset) {
this.in.list.offsets.pop()
this.html += `</ul>\n`
if (this.in.list.offsets.length == 0) {
@ -81,10 +74,8 @@ export class MarkDown {
}
}
}
}
if (sList == 'same') {
this.html += `<li>${matchUnOrdered[3]}</li>\n`
}
return true
}
return false