diff --git a/src/io/wordOffice.test.ts b/src/io/wordOffice.test.ts index f8eb518..5e9a703 100644 --- a/src/io/wordOffice.test.ts +++ b/src/io/wordOffice.test.ts @@ -349,6 +349,33 @@ describe("wordOffice helpers", () => { ]); }); + it("сохраняет пустые ячейки и строки таблицы для DOCX", async () => { + const html = ` + + + +

Итог
 
+ `; + const blocks = htmlToWordBlocks(html); + const blob = await exportDocxBlob("Пустая таблица.docx", html); + const zip = await JSZip.loadAsync(await blob.arrayBuffer()); + const documentXml = (await zip.file("word/document.xml")?.async("string")) ?? ""; + + expect(blocks).toEqual([ + { + type: "table", + rows: [ + ["", "", "Итог"], + ["", "", ""] + ] + } + ]); + expect(documentXml).toContain(""); + expect(documentXml.match(//g)).toHaveLength(2); + expect(documentXml.match(//g)).toHaveLength(6); + expect(documentXml).toContain("Итог"); + }); + it("сохраняет размер шрифта из HTML inline-стилей для DOCX", () => { const blocks = htmlToWordBlocks(`

Normal Large Pixel size

diff --git a/src/io/wordOffice.ts b/src/io/wordOffice.ts index db9b92e..560b2e1 100644 --- a/src/io/wordOffice.ts +++ b/src/io/wordOffice.ts @@ -647,11 +647,7 @@ function parseHtmlFragment(html: string) { function tableRows(table: Element) { return Array.from(table.querySelectorAll("tr")) - .map((row) => - Array.from(row.querySelectorAll("th,td")) - .map(elementText) - .filter((cell) => cell.length > 0) - ) + .map((row) => Array.from(row.querySelectorAll("th,td")).map(elementText)) .filter((row) => row.length > 0); }