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.
This commit is contained in:
parent
2f85d44428
commit
edf4c6588d
|
|
@ -125,6 +125,9 @@ body {
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
}
|
}
|
||||||
|
.chat-message-content thead {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
.chat-message-content-live {
|
.chat-message-content-live {
|
||||||
overflow-wrap: break-word;
|
overflow-wrap: break-word;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @param {string} line
|
||||||
*/
|
*/
|
||||||
process_table_line(line) {
|
process_table_line(line) {
|
||||||
//let lineParts = line.match(/^([|].*?)+?[|]$/)
|
if (!line.startsWith("|")) {
|
||||||
let lineParts = line.match(/^[|](\s*[^|]*\s*[|])+$/)
|
if (this.in.table.columns > 0) {
|
||||||
if (lineParts != null) {
|
this.html += "</tbody>\n"
|
||||||
|
this.html += "</table>\n"
|
||||||
|
this.in.table.columns = 0
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let lineA = line.split('|')
|
||||||
|
if (lineA.length > 2) {
|
||||||
if (this.in.table.columns == 0) {
|
if (this.in.table.columns == 0) {
|
||||||
// table heading
|
// table heading
|
||||||
this.html += "<table>\n<thead>\n"
|
this.html += "<table>\n<thead>\n<tr>\n"
|
||||||
for(let i=1; i<lineParts.length; i++) {
|
for(let i=1; i<lineA.length; i++) {
|
||||||
this.html += `<th>${lineParts[i]}</th>\n`
|
this.html += `<th>${lineA[i]}</th>\n`
|
||||||
}
|
}
|
||||||
this.html += "</thead>\n"
|
this.html += "</tr>\n</thead>\n"
|
||||||
this.in.table.columns = lineParts.length-1;
|
this.in.table.columns = lineA.length-2;
|
||||||
this.in.table.rawRow = 0
|
this.in.table.rawRow = 0
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (this.in.table.columns > 0) {
|
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")
|
console.log("DBUG:TypeMD:Table:NonHead columns mismatch")
|
||||||
}
|
}
|
||||||
this.in.table.rawRow += 1
|
this.in.table.rawRow += 1
|
||||||
|
|
@ -61,8 +71,8 @@ export class MarkDown {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
this.html += "<tr>\n"
|
this.html += "<tr>\n"
|
||||||
for(let i=1; i<lineParts.length; i++) {
|
for(let i=1; i<lineA.length; i++) {
|
||||||
this.html += `<td>${lineParts[i]}</td>\n`
|
this.html += `<td>${lineA[i]}</td>\n`
|
||||||
}
|
}
|
||||||
this.html += "</tr>\n"
|
this.html += "</tr>\n"
|
||||||
return true
|
return true
|
||||||
|
|
@ -72,6 +82,7 @@ export class MarkDown {
|
||||||
if (this.in.table.columns > 0) {
|
if (this.in.table.columns > 0) {
|
||||||
this.html += "</tbody>\n"
|
this.html += "</tbody>\n"
|
||||||
this.html += "</table>\n"
|
this.html += "</table>\n"
|
||||||
|
this.in.table.columns = 0
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue