diff --git a/src/converters/html-to-markdown.ts b/src/converters/html-to-markdown.ts index 61e1d9a..7d919b5 100644 --- a/src/converters/html-to-markdown.ts +++ b/src/converters/html-to-markdown.ts @@ -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; }, }); diff --git a/tests/converters/html-to-markdown.test.ts b/tests/converters/html-to-markdown.test.ts index e4865f4..48f57ab 100644 --- a/tests/converters/html-to-markdown.test.ts +++ b/tests/converters/html-to-markdown.test.ts @@ -288,7 +288,7 @@ 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 = `
| Header |