SimpleChatTCRV:MarkDown:Tables initial go

Rather this wont work, need to refresh on regex, been too long.

Rather using split should be simpler

However the extraction of head and body parts with seperation
inbetween for transition should work

Rather the seperation is blindly assumed and corresponding line
discarded for now
This commit is contained in:
hanishkvc 2025-11-26 01:01:04 +05:30
parent 3cc5bd01ae
commit 2f85d44428
1 changed files with 37 additions and 7 deletions

View File

@ -9,7 +9,10 @@ export class MarkDown {
constructor() { constructor() {
this.in = { this.in = {
preFenced: "", preFenced: "",
table: 0, table: {
columns: 0,
rawRow: 0,
},
/** @type {Array<number>} */ /** @type {Array<number>} */
listUnordered: [] listUnordered: []
} }
@ -32,21 +35,45 @@ export class MarkDown {
* @param {string} line * @param {string} line
*/ */
process_table_line(line) { process_table_line(line) {
let lineParts = line.match(/^(|.*)*|$/) //let lineParts = line.match(/^([|].*?)+?[|]$/)
let lineParts = line.match(/^[|](\s*[^|]*\s*[|])+$/)
if (lineParts != null) { if (lineParts != null) {
if (this.in.table == 0) { if (this.in.table.columns == 0) {
// table heading // table heading
this.html += "<table>\n<thead>\n" this.html += "<table>\n<thead>\n"
for(let i=1; i<lineParts.length; i++) { for(let i=1; i<lineParts.length; i++) {
this.html += `<th>${lineParts[i]}</th>\n` this.html += `<th>${lineParts[i]}</th>\n`
} }
this.html += "</thead>\n" this.html += "</thead>\n"
this.in.table = lineParts.length-1; this.in.table.columns = lineParts.length-1;
return this.in.table.rawRow = 0
return true
} }
if (this.in.table > 0) { if (this.in.table.columns > 0) {
if (this.in.table.columns != lineParts.length-1) {
console.log("DBUG:TypeMD:Table:NonHead columns mismatch")
}
this.in.table.rawRow += 1
if (this.in.table.rawRow == 1) {
// skip the table head vs body seperator
// rather skipping blindly without even checking if seperator or not.
this.html += "<tbody>\n"
return true
}
this.html += "<tr>\n"
for(let i=1; i<lineParts.length; i++) {
this.html += `<td>${lineParts[i]}</td>\n`
}
this.html += "</tr>\n"
return true
} }
console.warn("DBUG:TypeMD:Table:Thrisanku???")
} else {
if (this.in.table.columns > 0) {
this.html += "</tbody>\n"
this.html += "</table>\n"
}
return false
} }
} }
@ -65,6 +92,9 @@ export class MarkDown {
} }
return return
} }
if (this.process_table_line(line)) {
return
}
// 3 or more of --- or ___ or *** followed by space // 3 or more of --- or ___ or *** followed by space
// some online notes seemed to indicate spaces at end, so accepting same // some online notes seemed to indicate spaces at end, so accepting same
if (line.match(/^[-]{3,}|[*]{3,}|[_]{3,}\s*$/) != null) { if (line.match(/^[-]{3,}|[*]{3,}|[_]{3,}\s*$/) != null) {