diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index a06032d16f..f1cc075294 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -9,7 +9,10 @@ export class MarkDown { constructor() { this.in = { preFenced: "", - table: 0, + table: { + columns: 0, + rawRow: 0, + }, /** @type {Array} */ listUnordered: [] } @@ -32,21 +35,45 @@ export class MarkDown { * @param {string} line */ process_table_line(line) { - let lineParts = line.match(/^(|.*)*|$/) + //let lineParts = line.match(/^([|].*?)+?[|]$/) + let lineParts = line.match(/^[|](\s*[^|]*\s*[|])+$/) if (lineParts != null) { - if (this.in.table == 0) { + if (this.in.table.columns == 0) { // table heading this.html += "\n\n" for(let i=1; i${lineParts[i]}\n` } this.html += "\n" - this.in.table = lineParts.length-1; - return + this.in.table.columns = lineParts.length-1; + 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 += "\n" + return true + } + this.html += "\n" + for(let i=1; i${lineParts[i]}\n` + } + this.html += "\n" + return true } + console.warn("DBUG:TypeMD:Table:Thrisanku???") + } else { + if (this.in.table.columns > 0) { + this.html += "\n" + this.html += "
\n" + } + return false } } @@ -65,6 +92,9 @@ export class MarkDown { } return } + if (this.process_table_line(line)) { + return + } // 3 or more of --- or ___ or *** followed by space // some online notes seemed to indicate spaces at end, so accepting same if (line.match(/^[-]{3,}|[*]{3,}|[_]{3,}\s*$/) != null) {