Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/converters/html-to-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ function createTurndownService(): TurndownService {
const text = content.replace(/[\r\n]+/g, " ").replace(/\|/g, "\\|").trim();
const index = directCellIndex(node);
const prefix = index === 0 ? "| " : " ";
return prefix + text + " |";
const rawSpan = parseInt((node as HTMLElement).getAttribute?.("colspan") ?? "1", 10);
const span = Number.isFinite(rawSpan) && rawSpan > 1 ? rawSpan : 1;
const extra = span > 1 ? " |".repeat(span - 1) : "";
return prefix + text + " |" + extra;
},
});

Expand Down
6 changes: 3 additions & 3 deletions tests/converters/html-to-markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ describe("htmlToMarkdown", () => {
expect(result).toContain("| Magic Number | 17 |");
});

it("separator column count respects colspan on first-row cells", () => {
it("colspan cells emit extra empty columns to keep table width consistent", () => {
const html = `
<table>
<tr><td colspan="2">Header</td></tr>
<tr><td>Left</td><td>Right</td></tr>
</table>
`;
const result = htmlToMarkdown(html);
expect(result).toContain("| Header |");
expect(result).toContain("| Header | |");
expect(result).toContain("| --- | --- |");
expect(result).toContain("| Left | Right |");
});
Expand Down Expand Up @@ -351,7 +351,7 @@ describe("htmlToMarkdown", () => {
</div>
`;
const result = htmlToMarkdown(html);
expect(result).toContain("| someuser |");
expect(result).toContain("| someuser | |");
expect(result).toContain("| --- | --- |");
expect(result).toContain("| Magic Number | 17 |");
expect(result).toContain("| Job | Celebrity Nobody |");
Expand Down
Loading