Preserve QWord DOCX text colors on import

This commit is contained in:
Курнат Андрей
2026-06-01 05:39:55 +03:00
parent 9bf4dd3672
commit 04811e6580
3 changed files with 303 additions and 11 deletions
+23
View File
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import { exportDocxBlob, htmlToWordBlocks, importDocxFile } from "./wordOffice";
describe("wordOffice DOCX import", () => {
it("imports DOCX text color and highlight from OOXML", async () => {
const blob = await exportDocxBlob(
"Color.docx",
'<p><span style="color: #0f5fae; background-color: #fff2cc;">Color fragment</span></p>'
);
const file = new File([blob], "Color.docx", { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
const imported = await importDocxFile(file);
expect(imported.html).toContain("color: #0F5FAE;");
expect(imported.html).toContain("background-color: #FFF2CC;");
expect(htmlToWordBlocks(imported.html)).toEqual([
{
type: "paragraph",
text: "Color fragment",
runs: [{ text: "Color fragment", color: "0F5FAE", highlightColor: "FFF2CC" }]
}
]);
});
});