From edf4c6588dad92fc10b78d59d94fe34c2950123c Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Wed, 26 Nov 2025 01:19:18 +0530 Subject: [PATCH] SimpleChatTCRV:MarkDown:Table cleanup initial go Switch to the simpler split based flow. Include tr wrt the table head block also. Add a css entry to try and have header cell contents text aling to left for now, given that there is no border or color shaded or so distinguishing characteristics wrt the table cells for now. --- tools/server/public_simplechat/simplechat.css | 3 ++ tools/server/public_simplechat/typemd.mjs | 33 ++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/server/public_simplechat/simplechat.css b/tools/server/public_simplechat/simplechat.css index 4789666a3e..9b46a30c76 100644 --- a/tools/server/public_simplechat/simplechat.css +++ b/tools/server/public_simplechat/simplechat.css @@ -125,6 +125,9 @@ body { word-break: break-word; hyphens: auto; } +.chat-message-content thead { + text-align: left; +} .chat-message-content-live { overflow-wrap: break-word; word-break: break-word; diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index f1cc075294..4020d91e21 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -32,25 +32,35 @@ export class MarkDown { } /** + * Try extract a table from markdown content, + * one line at a time. + * This is a imperfect logic, but should give a rough semblance of a table many a times. * @param {string} line */ process_table_line(line) { - //let lineParts = line.match(/^([|].*?)+?[|]$/) - let lineParts = line.match(/^[|](\s*[^|]*\s*[|])+$/) - if (lineParts != null) { + if (!line.startsWith("|")) { + if (this.in.table.columns > 0) { + this.html += "\n" + this.html += "\n" + this.in.table.columns = 0 + } + return false + } + let lineA = line.split('|') + if (lineA.length > 2) { if (this.in.table.columns == 0) { // table heading - this.html += "\n\n" - for(let i=1; i${lineParts[i]}\n` + this.html += "
\n\n\n" + for(let i=1; i${lineA[i]}\n` } - this.html += "\n" - this.in.table.columns = lineParts.length-1; + this.html += "\n\n" + this.in.table.columns = lineA.length-2; this.in.table.rawRow = 0 return true } if (this.in.table.columns > 0) { - if (this.in.table.columns != lineParts.length-1) { + if (this.in.table.columns != lineA.length-2) { console.log("DBUG:TypeMD:Table:NonHead columns mismatch") } this.in.table.rawRow += 1 @@ -61,8 +71,8 @@ export class MarkDown { return true } this.html += "\n" - for(let i=1; i${lineParts[i]}\n` + for(let i=1; i${lineA[i]}\n` } this.html += "\n" return true @@ -72,6 +82,7 @@ export class MarkDown { if (this.in.table.columns > 0) { this.html += "\n" this.html += "
\n" + this.in.table.columns = 0 } return false }