// HTML's and as Word's tracked changes (issue #2632): an HTML diff, such as htmldiff writes, written with // the trackChanges option, so Word shows each change for its reader to accept or reject. See docs/usage/html.md. import * as fs from "fs"; import { Document, Packer } from "docx"; import { htmlToContent } from "docx/html"; const diff = `

Payment terms

Invoices are due within 3045 days of receipt.

Late payments carry interest of 2%1.5% a month.

Either party may end this agreement with 30 days' notice.

`; const doc = new Document({ sections: [{ children: [...htmlToContent(diff, { trackChanges: { author: "Legal", date: "2026-10-13T09:00:00Z" } })] }], }); Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer); });