Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: preserve editor list bullets in Word exports (RX-148) (#3769)

Amruth Pillaid44a101bc920
diff --git a/apps/web/src/features/resume/export/use-resume-export.test.ts b/apps/web/src/features/resume/export/use-resume-export.test.ts
index 99e5b0410..9ba4ee027 100644
--- a/apps/web/src/features/resume/export/use-resume-export.test.ts
+++ b/apps/web/src/features/resume/export/use-resume-export.test.ts
@@ -31,3 +31,19 @@ it.each(["docx", "odt"] as const)(
}
},
);
+
+it("marks editor list paragraphs in browser Word downloads", async () => {
+ const data = structuredClone(defaultResumeData);
+ data.basics.name = "Ada Lovelace";
+ data.summary.content = "<ul><li><p>Editor bullet</p></li><li>Plain bullet</li></ul>";
+ const blob = await createExportFile({ name: "Ada", slug: "ada", data }, "docx");
+ const files = unzipSync(new Uint8Array(await blob.arrayBuffer()));
+ const documentXml = files["word/document.xml"];
+ const numberingXml = files["word/numbering.xml"];
+ if (!documentXml || !numberingXml) throw new Error("Missing Word list definitions");
+ const xml = strFromU8(documentXml);
+ expect(xml.match(/<w:numPr>/g)).toHaveLength(2);
+ expect(xml).toContain("Editor bullet");
+ expect(xml).toContain("Plain bullet");
+ expect(strFromU8(numberingXml)).toContain('<w:numFmt w:val="bullet"/>');
+});
diff --git a/packages/api/src/features/documents/exports.test.ts b/packages/api/src/features/documents/exports.test.ts
index dcf3179b2..68b11bc35 100644
--- a/packages/api/src/features/documents/exports.test.ts
+++ b/packages/api/src/features/documents/exports.test.ts
@@ -40,6 +40,29 @@ it("exports saved data as round-trippable JSON, readable Markdown and a Word doc
expect(getResume).toHaveBeenCalledWith({ id: "resume-1", userId: "owner" });
});
+it("keeps editor list markers in the Word export used by API and native clients", async () => {
+ const data = structuredClone(defaultResumeData);
+ data.basics.name = "Ada Lovelace";
+ data.summary.content = "<p>Plain paragraph</p><ul><li><p>Editor bullet</p></li><li>Plain bullet</li></ul>";
+ getResume.mockResolvedValue({ id: "resume-1", name: "Ada", data });
+ const docx = await call(documentExports.resume, { id: "resume-1", format: "docx" }, { context });
+ const files = unzipSync(new Uint8Array(await docx.body.arrayBuffer()));
+ const documentXml = files["word/document.xml"];
+ const numberingXml = files["word/numbering.xml"];
+ if (!documentXml || !numberingXml) throw new Error("Missing Word list definitions");
+ const xml = strFromU8(documentXml);
+ const plainParagraph = xml
+ .match(/<w:p[ >][\s\S]*?<\/w:p>/g)
+ ?.find((paragraph) => paragraph.includes("Plain paragraph"));
+ expect(plainParagraph).toContain("Plain paragraph");
+ expect(plainParagraph).not.toContain("<w:numPr>");
+ expect(plainParagraph).not.toContain("ListParagraph");
+ expect(xml.match(/<w:numPr>/g)).toHaveLength(2);
+ expect(xml).toContain("Editor bullet");
+ expect(xml).toContain("Plain bullet");
+ expect(strFromU8(numberingXml)).toContain('<w:numFmt w:val="bullet"/>');
+});
+
it("exports an editable OpenDocument Text file", async () => {
const odt = await call(documentExports.resume, { id: "resume-1", format: "odt" }, { context });
expect(odt.headers["content-disposition"]).toContain(".odt");
diff --git a/packages/docx/src/html-to-docx.test.ts b/packages/docx/src/html-to-docx.test.ts
index b68d130aa..7690b1581 100644
--- a/packages/docx/src/html-to-docx.test.ts
+++ b/packages/docx/src/html-to-docx.test.ts
@@ -1,8 +1,17 @@
// @vitest-environment happy-dom
import { describe, expect, it } from "vite-plus/test";
+import { Document } from "docx";
import { htmlToParagraphs } from "./html-to-docx";
+function paragraphXml(html: string) {
+ const paragraphs = htmlToParagraphs(html);
+ const file = new Document({ sections: [{ children: paragraphs }] });
+ return paragraphs.map((paragraph) =>
+ JSON.stringify(paragraph.prepForXml({ file, viewWrapper: file.Document, stack: [] })),
+ );
+}
+
describe("htmlToParagraphs", () => {
it("converts plain text nodes at the body root into a paragraph", () => {
const result = htmlToParagraphs("Just some plain text");
@@ -24,3 +33,43 @@ describe("htmlToParagraphs", () => {
expect(json).not.toContain("alert(1)");
});
});
+
+describe("list paragraphs", () => {
+ it("marks editor paragraphs inside list items as list paragraphs", () => {
+ const [editor] = paragraphXml("<ul><li><p>Typed bullet</p></li></ul>");
+ const [plain] = paragraphXml("<ul><li>Typed bullet</li></ul>");
+
+ for (const xml of [editor, plain]) {
+ expect(xml).toContain('"w:numPr"');
+ expect(xml).toContain('"w:ilvl":{"_attr":{"w:val":0}');
+ expect(xml).toContain('"w:numId":{"_attr":{"w:val":1}');
+ expect(xml).toContain('"w:pStyle":{"_attr":{"w:val":"ListParagraph"}');
+ }
+ expect(editor).toBe(plain);
+ });
+
+ it("keeps nested list paragraphs at their own numbering level", () => {
+ const [outer, inner] = paragraphXml("<ul><li><p>Outer</p><ul><li><p>Inner</p></li></ul></li></ul>");
+
+ expect(outer).toContain('"w:ilvl":{"_attr":{"w:val":0}');
+ expect(inner).toContain('"w:ilvl":{"_attr":{"w:val":1}');
+ expect(outer).toContain("Outer");
+ expect(inner).toContain("Inner");
+ });
+
+ it("keeps every paragraph of a multi-paragraph list item", () => {
+ const xml = paragraphXml("<ul><li><p>First</p><p>Second</p></li></ul>");
+
+ expect(xml).toHaveLength(2);
+ expect(xml[0]).toContain("First");
+ expect(xml[1]).toContain("Second");
+ expect(xml.every((paragraph) => paragraph.includes('"w:numPr"'))).toBe(true);
+ });
+
+ it("keeps ordered list paragraphs marked, matching the existing list rendering", () => {
+ const [item] = paragraphXml("<ol><li><p>First</p></li></ol>");
+
+ expect(item).toContain('"w:numPr"');
+ expect(item).toContain("First");
+ });
+});
diff --git a/packages/docx/src/html-to-docx.ts b/packages/docx/src/html-to-docx.ts
index 71de4cf6f..0c9107385 100644
--- a/packages/docx/src/html-to-docx.ts
+++ b/packages/docx/src/html-to-docx.ts
@@ -174,9 +174,12 @@ function processBlockElement(
if (tag === "P" || tag === "DIV") {
const inlineChildren = collectInlineChildren(el, mergedStyle);
if (inlineChildren.length > 0) {
+ // The editor wraps list item text in <p>; keep the item's marker instead of recursing as a plain paragraph.
+ const bulletLevel = tag === "P" ? listLevel : undefined;
paragraphs.push(
new Paragraph({
children: inlineChildren,
+ ...(bulletLevel != null ? { bullet: { level: bulletLevel } } : {}),
...(tag === "P" && indent ? { indent } : quoteIndent ? { indent: { start: quoteIndent } } : {}),
}),
);