fix: rendering failed table (#160)

`---` 两端存在 `\t` 导致无法表格成功渲染
This commit is contained in:
YangQi 2022-07-27 14:09:06 +08:00 committed by GitHub
parent 64ead3b714
commit 0289f389d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -304,18 +304,15 @@ export function exportHTML() {
*/ */
export function createTable({ data, rows, cols }) { export function createTable({ data, rows, cols }) {
let table = `` let table = ``
let currRow = []
for (let i = 0; i < rows + 2; ++i) { for (let i = 0; i < rows + 2; ++i) {
table += `|\t` table += `| `
currRow = [] const currRow = []
for (let j = 0; j < cols; ++j) { for (let j = 0; j < cols; ++j) {
const rowIdx = i > 1 ? i - 1 : i const rowIdx = i > 1 ? i - 1 : i
i === 1 currRow.push(i === 1 ? `---` : data[`k_${rowIdx}_${j}`] || ` `)
? currRow.push(`---\t`)
: currRow.push(data[`k_${rowIdx}_${j}`] || ``)
} }
table += currRow.join(`\t|\t`) table += currRow.join(` | `)
table += `\t|\n` table += ` |\n`
} }
return table return table