fix: markdown table renders separator row as visible data (#1252)
* fix: markdown table renders separator row as visible data The alignment separator (|---|---|) at row index 1 was rendered as a <td> row with dashes as cell content. Skip it and only open <tbody> at that point, so tables render as header + data without the garbage separator row in between. * test: add regression test for table separator row rendering Verifies that the markdown table renderer skips the separator row (|---|---|) instead of rendering it as a visible data row. Also updates the test harness to handle the splitTableRow import.
This commit is contained in:
committed by
GitHub
parent
9c68ceafeb
commit
5452bc96b1
@@ -536,16 +536,18 @@ export function mdToHtml(src) {
|
||||
let html = '<table style="border-collapse: collapse; width: 100%; margin: 10px 0;">';
|
||||
|
||||
rows.forEach((row, idx) => {
|
||||
if (idx === 1 && /^[\s|:\-]+$/.test(row)) {
|
||||
html += '<tbody>';
|
||||
return;
|
||||
}
|
||||
const cells = splitTableRow(row);
|
||||
if (cells.length === 0) return;
|
||||
|
||||
html += idx === 1 ? '<tbody>' : '';
|
||||
html += '<tr>';
|
||||
|
||||
cells.forEach(cell => {
|
||||
const tag = idx === 0 ? 'th' : 'td';
|
||||
const style = idx === 1 ? 'style="border-top: 2px solid var(--red);"' : '';
|
||||
html += `<${tag} ${style} style="padding: 8px; text-align: left; border-bottom: 1px solid var(--border);">${cell.trim()}</${tag}>`;
|
||||
html += `<${tag} style="padding: 8px; text-align: left; border-bottom: 1px solid var(--border);">${cell.trim()}</${tag}>`;
|
||||
});
|
||||
|
||||
html += '</tr>';
|
||||
|
||||
Reference in New Issue
Block a user