SimpleChatTCRV:MarkDown:Cleanup Unordered list initial go

Ensure '---' is treated as a horizontal line and doesnt mess with
unordered list handling.

Take care of unwinding the unordered list everywhere it is needed.
This commit is contained in:
hanishkvc 2025-11-25 21:55:39 +05:30
parent be528bc34f
commit c420f16504
1 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,5 @@
//@ts-check //@ts-check
// Helpers to handle markdown content // simple minded helpers to handle markdown content
// by Humans for All // by Humans for All
// //
@ -17,13 +17,23 @@ export class MarkDown {
this.html = "" this.html = ""
} }
unwind_list_unordered() {
for(const i in this.in.listUnordered) {
this.html += "</ul>\n"
}
this.in.listUnordered.length = 0
}
unwind_list() {
this.unwind_list_unordered()
}
/** /**
* Process a line from markdown content * Process a line from markdown content
* @param {string} line * @param {string} line
*/ */
process_line(line) { process_line(line) {
let lineA = line.split(' ') let lineA = line.split(' ')
let lineRStripped = line.trimStart()
if (this.in.pre) { if (this.in.pre) {
if (lineA[0] == '```') { if (lineA[0] == '```') {
this.in.pre = false this.in.pre = false
@ -33,13 +43,20 @@ export class MarkDown {
} }
return return
} }
if (line == '---') {
this.unwind_list()
this.html += "<hr>\n"
return
}
if (line.startsWith ("#")) { if (line.startsWith ("#")) {
this.unwind_list()
let hLevel = lineA[0].length let hLevel = lineA[0].length
this.html += `<h${hLevel}>${line.slice(hLevel)}</h${hLevel}>\n` this.html += `<h${hLevel}>${line.slice(hLevel)}</h${hLevel}>\n`
return return
} }
let matchPre = line.match(/^```([a-zA-Z0-9]*)(.*)/); let matchPre = line.match(/^```([a-zA-Z0-9]*)(.*)/);
if ( matchPre != null) { if ( matchPre != null) {
this.unwind_list()
this.in.pre = true this.in.pre = true
this.html += `<pre class="${matchPre[1]}">\n` this.html += `<pre class="${matchPre[1]}">\n`
return return
@ -77,6 +94,7 @@ export class MarkDown {
} }
return return
} }
this.unwind_list()
this.html += `<p>${line}</p>` this.html += `<p>${line}</p>`
} }