SimpleChatTCRV:Markdown:Unordered list initial go
This commit is contained in:
parent
c9ddb90aae
commit
be528bc34f
|
|
@ -10,6 +10,8 @@ export class MarkDown {
|
||||||
this.in = {
|
this.in = {
|
||||||
pre: false,
|
pre: false,
|
||||||
table: false,
|
table: false,
|
||||||
|
/** @type {Array<number>} */
|
||||||
|
listUnordered: []
|
||||||
}
|
}
|
||||||
this.md = ""
|
this.md = ""
|
||||||
this.html = ""
|
this.html = ""
|
||||||
|
|
@ -42,6 +44,39 @@ export class MarkDown {
|
||||||
this.html += `<pre class="${matchPre[1]}">\n`
|
this.html += `<pre class="${matchPre[1]}">\n`
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let matchUnOrdered = line.match(/^([ ]*)[-*][ ](.*)$/);
|
||||||
|
if ( matchUnOrdered != null) {
|
||||||
|
let sList = 'none'
|
||||||
|
let listLvl = 0
|
||||||
|
if (this.in.listUnordered.length == 0) {
|
||||||
|
sList = 'next'
|
||||||
|
this.in.listUnordered.push(matchUnOrdered[1].length)
|
||||||
|
listLvl = this.in.listUnordered.length // ie 1
|
||||||
|
} else {
|
||||||
|
if (this.in.listUnordered[this.in.listUnordered.length-1] < matchUnOrdered[1].length){
|
||||||
|
sList = 'next'
|
||||||
|
this.in.listUnordered.push(matchUnOrdered[1].length)
|
||||||
|
listLvl = this.in.listUnordered.length
|
||||||
|
} else if (this.in.listUnordered[this.in.listUnordered.length-1] == matchUnOrdered[1].length){
|
||||||
|
sList = 'same'
|
||||||
|
} else {
|
||||||
|
sList = 'same'
|
||||||
|
while (this.in.listUnordered[this.in.listUnordered.length-1] > matchUnOrdered[1].length) {
|
||||||
|
this.in.listUnordered.pop()
|
||||||
|
this.html += `</ul>\n`
|
||||||
|
if (this.in.listUnordered.length == 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sList == 'same') {
|
||||||
|
this.html += `<li>${line}</li>\n`
|
||||||
|
} else if (sList == 'next') {
|
||||||
|
this.html += `<ul>\n<li>${line}</li>\n`
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
this.html += `<p>${line}</p>`
|
this.html += `<p>${line}</p>`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue