diff --git a/src/io/wordOffice.ts b/src/io/wordOffice.ts index 9848e8c..358a7c0 100644 --- a/src/io/wordOffice.ts +++ b/src/io/wordOffice.ts @@ -1493,7 +1493,7 @@ function docxRunToHtml(run: unknown, imageDataByRelationshipId: DocxImageDataByR if (hasDocxBoolean(properties, "w:i")) { html = `${html}`; } - if (hasDocxBoolean(properties, "w:u")) { + if (hasDocxUnderline(properties)) { html = `${html}`; } if (hasStrike) { @@ -1707,6 +1707,15 @@ function hasDocxBoolean(properties: XmlRecord, key: string) { return !["0", "false", "off"].includes(value.toLowerCase()); } +function hasDocxUnderline(properties: XmlRecord) { + if (!Object.prototype.hasOwnProperty.call(properties, "w:u")) { + return false; + } + + const value = (docxAttribute(childRecord(properties, "w:u"), "w:val") || docxAttribute(childRecord(properties, "w:u"), "val")).trim().toLowerCase(); + return !["0", "false", "off", "none"].includes(value); +} + function childRecord(value: unknown, key: string): XmlRecord { const child = asRecord(value)[key]; if (Array.isArray(child)) { diff --git a/src/io/wordOfficeImport.test.ts b/src/io/wordOfficeImport.test.ts index edbacc5..14d3878 100644 --- a/src/io/wordOfficeImport.test.ts +++ b/src/io/wordOfficeImport.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from "vitest"; +import JSZip from "jszip"; import { exportDocxBlob, htmlToWordBlocks, importDocxFile } from "./wordOffice"; const tinyPngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII="; @@ -128,6 +129,36 @@ describe("wordOffice DOCX import", () => { ]); }); + it("does not import DOCX underline when w:u val is none", async () => { + const sourceBlob = await exportDocxBlob("UnderlineNone.docx", '
Not underlined
'); + const zip = await JSZip.loadAsync(await sourceBlob.arrayBuffer()); + const documentXml = (await zip.file("word/document.xml")?.async("string")) ?? ""; + const patchedDocumentXml = documentXml.replace(/(H2O m2
"); const file = new File([blob], "Indexes.docx", {