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:
parent
e7b8fc1392
commit
9b75e494be
|
|
@ -54,37 +54,28 @@ export class MarkDown {
|
||||||
// spaces followed by - or + or * followed by a space and actual list item
|
// spaces followed by - or + or * followed by a space and actual list item
|
||||||
let matchUnOrdered = line.match(/^([ ]*)([-+*]|[a-zA-Z0-9]\.)[ ](.*)$/);
|
let matchUnOrdered = line.match(/^([ ]*)([-+*]|[a-zA-Z0-9]\.)[ ](.*)$/);
|
||||||
if (matchUnOrdered != null) {
|
if (matchUnOrdered != null) {
|
||||||
let sList = 'none'
|
|
||||||
let listLvl = 0
|
let listLvl = 0
|
||||||
let curOffset = matchUnOrdered[1].length
|
let curOffset = matchUnOrdered[1].length
|
||||||
if (this.in.list.offsets.length == 0) {
|
let lastOffset = this.in.list.offsets[this.in.list.offsets.length-1];
|
||||||
sList = 'same'
|
if (lastOffset == undefined) {
|
||||||
|
lastOffset = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastOffset < curOffset){
|
||||||
this.in.list.offsets.push(curOffset)
|
this.in.list.offsets.push(curOffset)
|
||||||
listLvl = this.in.list.offsets.length // ie 1
|
listLvl = this.in.list.offsets.length
|
||||||
this.html += "<ul>\n"
|
this.html += "<ul>\n"
|
||||||
} else {
|
} else if (lastOffset > curOffset){
|
||||||
let lastOffset = this.in.list.offsets[this.in.list.offsets.length-1];
|
while (this.in.list.offsets[this.in.list.offsets.length-1] > curOffset) {
|
||||||
if (lastOffset < curOffset){
|
this.in.list.offsets.pop()
|
||||||
sList = 'same'
|
this.html += `</ul>\n`
|
||||||
this.in.list.offsets.push(curOffset)
|
if (this.in.list.offsets.length == 0) {
|
||||||
listLvl = this.in.list.offsets.length
|
break
|
||||||
this.html += "<ul>\n"
|
|
||||||
} else if (lastOffset == curOffset){
|
|
||||||
sList = 'same'
|
|
||||||
} else {
|
|
||||||
sList = 'same'
|
|
||||||
while (lastOffset > curOffset) {
|
|
||||||
this.in.list.offsets.pop()
|
|
||||||
this.html += `</ul>\n`
|
|
||||||
if (this.in.list.offsets.length == 0) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sList == 'same') {
|
|
||||||
this.html += `<li>${matchUnOrdered[3]}</li>\n`
|
this.html += `<li>${matchUnOrdered[3]}</li>\n`
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue