Commit Graph
352 Commits
Author SHA1 Message Date
Dolan 19da2bf8b7 docs: explain that a table row of exact height never splits across pages (#3852) 2026-10-27 16:16:02 +00:00
Dolan 922f7f5fd9 docs: say Packer.toBuffer rejects in a browser, which has no Buffer, rather than giving a Uint8Array (#3845) 2026-10-26 16:00:47 +00:00
Dolan ab3a09807c fix: emit toStream's failure to zip on its error event, as in a browser without Buffer, not as an unhandled rejection (#3844) 2026-10-26 15:30:15 +00:00
DolanandClaude Opus 5.5 66eaf1c12e feat: read the theme of a Word document or template with readTheme, and theme fonts for other scripts (#878) (#3839)
* feat: Word's themes, colors and fonts, and the theme of a Word document or template, from docx/theme (#878)

docx/theme is a new optional entry, so the main bundle stays as it is:

- Themes: the 29 themes of Word's Design > Themes gallery, each with its
  name, colors, and fonts for headings and body text, as IThemeOptions.
- ColorSchemes and FontSchemes: the 24 color sets and 26 font sets of the
  Design > Colors and Design > Fonts galleries, to mix with a theme as
  Word's Design tab does.
- readTheme: the theme of a .docx, .docm, .dotx, .dotm, .pptx, .xlsx or
  .thmx file, or of a theme1.xml, or colors or fonts Word saved on their
  own. Styles taken from a template with externalStyles then keep the
  template's theme fonts and colors (#878).

The presets are generated from Word for Mac's own theme files by
scripts/generate-word-themes.ts, which reads each one with readTheme.

In docx, a theme font can now have a font for each script (scripts, by
ISO 15924 code), in place of Office's for those scripts, so Word's themes
keep their own fonts for Japanese, Chinese and other scripts. docx also
exports parseXml and unzipFiles, which it already had, so docx/theme
reads files without bundling a second XML parser and unzipper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* refactor: read a template's theme with readTheme from docx, sharing the patcher's theme reader, without docx/theme (#878)

- Word's themes, colour sets and font sets (Themes, ColorSchemes, FontSchemes), the
  script that generated them and the docx/theme entry are dropped. #878 asks only for
  the theme of the template a document's styles come from.
- readTheme moves into the core and is exported from docx. The patcher reads the
  colours of a template's theme with the same code, so parseXml and unzipFiles stay
  internal.
- The paths of a package's parts and its relationships' targets (relationshipsPathOf,
  resolveTarget and the others) move from the patcher to src/util/package-paths.ts,
  so the theme reader in src/file can use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: read a theme in UTF-16, and inflate only a package's relationships and its theme in readTheme

- A theme, or the XML of one, that starts with UTF-16's byte order mark is read as
  UTF-16, little or big endian, as XML may be written.
- readTheme inflates a package's relationships, and then only the theme they refer to,
  so a large or damaged document, presentation or workbook part doesn't take memory or
  stop it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: find a theme whose relationship's target is in another case than its part, in readTheme and the patcher

The Open Packaging Conventions compare part names without regard to case, so a
relationship's target such as "Theme/THEME1.xml" names word/theme/theme1.xml.
readTheme threw that the file has no theme, and patchDocument used Office's colours.
isSamePart, in src/util/package-paths.ts, compares them as drawing-patch already finds
a relationship's target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:02:10 +00:00
DolanandClaude Opus 5.5 82b1dc132e fix: write a table lined up inline down the page in line with the text, as Word floats one with w:tblpYSpec="inline" (#331) (#3838)
A table with `float: { relativeVerticalPosition: RelativeVerticalPosition.INLINE }` was written with
`w:tblpYSpec="inline"` in its `w:tblpPr`. Word has no floating table in line with the text: it places such a table
at the top of the paragraph after it, with text beside it, and saves it back with the `inline` dropped
(`<w:tblpPr w:vertAnchor="text" w:tblpXSpec="center"/>`). So the table never stayed in line with the text, as the
option promises.

Such a table is now written in line with the text, as Word writes a table with no text wrapping: without
`w:tblpPr` or `w:tblOverlap`. Its `relativeHorizontalPosition` of left, center or right becomes its `w:jc`, as Word's
row alignment reports those of a floating table, unless the table has an `alignment` of its own. Word reads the
issue's table as not wrapping text and centered, and lays it out centered between the paragraphs before and after it.

The tables docs now show `alignment`, and say what `INLINE` writes.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 13:10:40 +00:00
Dolan ba1e9ddea9 fix: show Word's Update Table on a table of contents, by putting it in Word's Table of Contents gallery (#2598) (#3833) 2026-10-24 14:35:24 +01:00
DolanandClaude Opus 5.5 b26d269153 feat: make a new paragraph with other options from a paragraph, with Paragraph's with() (#3330) (#3831)
paragraph.with({ indent }) makes a new paragraph with the paragraph's options and those given, which replace its
own, such as to lay out the paragraphs a parser made, without casting to reach their children. The paragraph is
left as it is. paragraph.options gives the options it was made with, so an option can be extended rather than
replaced.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 01:00:44 +01:00
DolanandClaude Opus 5.5 2f8c8c7711 feat: patch placeholders with spaces inside their delimiters, such as {{ name }}, with trimPlaceholders (#3112) (#3830)
patchDocument's trimPlaceholders takes the spaces inside the delimiters out of the placeholders of the patches given,
even when Word splits them across runs, before patching: in the text, the fields of TABLE_ROWS patches, and the alt
text of drawings. patchDetector's trimPlaceholders gives their keys without the spaces. Both default to false.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 01:00:36 +01:00
DolanandClaude Opus 5.5 414b476dde fix: give a drawing whose alt text has no name an empty name, which the XML requires (#3829)
An ImageRun, ChartRun or shape whose altText was only a description, as JavaScript allows, wrote wp:docPr without
its required name attribute. The name now defaults to empty, as it does for a drawing without alt text, and is
optional in DocPropertiesOptions, so alt text can be just a description.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 01:00:30 +01:00
Dolan 72951b75f7 feat: replace the image of a picture in a template, keeping its look, with ImagePatch (#3072) (#3828) 2026-10-23 22:02:17 +01:00
DolanandClaude Opus 5.5 eadca504e2 fix: define the TOC 1 to TOC 9 styles, so LibreOffice keeps the levels of a table of contents indented (#3819) (#3821)
* fix: define the TOC 1 to TOC 9 styles, so LibreOffice keeps the levels of a table of contents indented (#3819)

Since 9.9.0 a table of contents is written with its entries, in the styles
TOC1 to TOC9, which docx never defined. Opening it, LibreOffice gives its
Contents 2 to Contents 9 styles no indent, so once it updates the index every
level is flush left. 9.8.1 wrote no entries, and LibreOffice kept its own
indents.

docx now writes the styles as Word adds them: based on Normal, 5 points of
space after, and each level indented by Normal's font size more than the one
above (200 twips a level at docx's default 10 points, 220 at 11 points, as
Word for Mac writes them). They are hidden until used, as Word's are. A style
with their id replaces them, as for the other default styles, and so does a
style with their name, such as a template's "toc 1" with a localized id, so
no two styles share a name. The entries no longer need an indent of their
own, which assumed 220 twips.

Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep the text-and-spacing layout demo's Tab stops heading clear of the bottom of a page

The TOC styles give the table of contents' entries 5 points of space after,
as Word's do, instead of the demo's 8, so the text after the table moved up
33 points. That left the Tab stops heading and its first line ending less
than a point below the bottom margin of page 9. Word and docx/layout fit
them there; LibreOffice, which compare-layout.sh checks against, moves them
to page 10. Word and LibreOffice put every other line of the page in the same
place.

The hanging-indent paragraph above the heading has 80 words instead of 90, a
line fewer, so the heading fits with room to spare. All 368 headings of the
layout demos are now on LibreOffice's page, and Word puts this demo's on the
same pages.

Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep docx's TOC styles beside a character style with their name

Only a paragraph style named "toc 1" to "toc 9" takes the place of docx's
TOC1 to TOC9. A table of contents' entries are paragraphs, which can't take
a character style, so a character style named "toc 2" left the entries
naming a TOC2 that docx no longer wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: indent the TOC styles patchDocument adds by the template's Normal font size

Word indents each level of a table of contents by the size of the Normal
style's font, and a Document does too, but the TOC1 to TOC9 styles that
patchDocument adds to a template without them always stepped by docx's 10
points. They now follow the template's Normal: its own size, or else the
document's default size, such as the 12 points Word for Mac saves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: take the TOC indent from the template's style that patchDocument bases the TOC styles on

The TOC styles patchDocument adds are based on the template's style with
Normal's id, or else on its style named Normal. Their indent now follows
the font size of that same style, so a template whose Normal has another
name still gets its size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 04:09:31 +01:00
Dolan 799bc7f47e feat: choose what fills the space before a table of contents' page numbers, such as nothing or hyphens (#1696) (#3818) 2026-10-22 10:41:12 +01:00
DolanandClaude Opus 5.5 5050cc0bba feat: draw diagonal lines across table cells, to split a header cell (#3121) (#3817)
A cell's borders take `diagonalDown` and `diagonalUp`, Word's "Diagonal
Down Border" and "Diagonal Up Border", written as `w:tl2br` and `w:tr2bl`
after the sides, in CT_TcBorders' order. A diagonal down border splits a
header cell into a label for the columns, above the line, and one for the
rows, below it.

Checked in Word for Mac: a cell merged with columnSpan or rowSpan gets one
diagonal across the whole merged cell. docx already copies a merged cell's
borders into the cells it adds below, and Word draws the same either way,
as it keeps the diagonal on the cells below when it saves.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 03:18:59 +01:00
DolanandClaude Opus 5.5 8a84c5906d fix: write a half-inch default tab stop, so tabs and list text line up in Pages (#2590) (#3816)
docx only wrote w:defaultTabStop when the defaultTabStop option was set. The
spec puts a tab stop every half inch without it, and Word and LibreOffice do,
but Pages 15.1.1 puts none: a tab takes no room, and the tab after a list
number with no hanging indent sends the text to the right margin, one word to
a line. Write 720 unless the option says otherwise, as Word always does.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 02:37:02 +01:00
DolanandClaude Opus 5.5 b87383272d feat: cite sources and list them in a bibliography, in each of Word's styles, from docx/bibliography (#557) (#3814)
* feat(bibliography): the sources part, the styles' framework, and Word's output to test against

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): citations and bibliographies, written as Word's content controls and fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test(bibliography): keep the empty paragraphs in corpus s's bibliographies of GB7714 and ISO 690

The fixtures' generator left out the paragraphs of corpus s's bibliographies that have
no text, though Word's styles write them: GB7714 and ISO 690 write an entry for a source
with no author, title or other field as an empty paragraph, which Word keeps. Corpora a
to d, Word's own output, keep empty paragraphs between entries too. Each of these
fixtures gets back its 15 empty paragraphs, from the oracle, with the others as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in GB7714, as Word does

GB.XSL and ISO690.XSL share nearly every template, so the shared ones go
in one family module, iso-690-family.ts, with the few that differ chosen by
the variant: GB7714 cites a source with no author or year by its tag, and
the two styles put the space after a website's or a report's production
company by different fields.

The module also reads the styles' HTML as Word's import does: spaces
collapse, a space falls between two elements and at the end of a copied
variable before the end of a paragraph, and a copied element with nothing
in it leaves its formatting on for the rest of the bibliography.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in ISO 690 by first element and date, as Word does

ISO690.XSL is GB.XSL's twin, so the style is the ISO 690 variant of the
family module: a source with a title but no author or year is cited by
nothing, "()", where GB7714 cites it by its tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in ISO 690 by numerical reference, as Word does

ISO690Nmerical.XSL cites a source by its number, with the pages or volume
cited after it, such as "(1 p. 5)", and lists the sources in the order the
document cites them. Its entries are the ISO 690 family's, with the main
contributors after the start of a journal article or conference paper.

The style copies each entry from a variable, so Word reads an entry whose
bold has nothing in it, such as one with no author, as bold that stays on
for the rest of the bibliography. An empty xsl:value-of in an element ends
it as usual, so a miscellaneous source with no publication doesn't leave
italics on, as Word's own bibliography of such a source shows; libxslt's
output differs from Word's there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* chore(bibliography): spell the styles' names and Word's abbreviations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test(bibliography): keep the empty entries of corpus s in the GOST and SIST02 fixtures

Word writes an empty paragraph for a source whose entry is empty in a style,
such as a miscellaneous source with no fields in GOST, as Word's style writes an
empty <p> for it. gen-fixtures.mjs dropped every empty paragraph of corpus s, so
the fixtures had fewer entries than the bibliography. They're rewritten from the
oracle with them, and gen-fixtures.mjs needs the same change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in GOST, as Word does

Ports Word's GOST - Name Sort (GostName.XSL) and GOST - Title Sort
(GostTitle.XSL). They share everything but how an entry starts, how the
bibliography is sorted, and a few templates, so both are written from one module,
gost-family.ts: Name Sort starts an entry with its authors in bold and leaves the
people who are those authors out of the rest; Title Sort starts it with its title
in bold, sorts by title, then the main author's names, counts an organization as a
book section's author, and writes an interview's responsibilities only when one
of the first three isn't empty.

The ports follow the templates where they do what they don't look like they do:
_MaxAuthor is read without a $, so every author is listed up to three; a role is
written only when one of its people has a last name; a location with neither a
city nor a publisher is the source's distributor; and an entry of nothing but
spaces is left empty, with no dot.

Their output matches Word's for corpora a to d and the oracle's for corpus s, and
the oracle's for 8 seeds of 300 random sources each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test(bibliography): end SIST02's corpus s entries without a space, as Word does

Word's SIST02 style, run with libxslt, ends an entry that ends with a bold or
italic element with a line break, which the oracle reads as a space. Word for
Mac shows none: corpus b has "<b>MoraLuz</b> <i>Bread.</i>" and
"<i>Untitled Notes.</i>", with nothing after them. Corpus s's expected
bibliography is regenerated with the oracle reading no space at the end of a
SIST02 paragraph, which changes 14 entries such as "<b>—.</b> ".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in SIST02, as Word does

Word's SIST02 style (SIST02.XSL), with its own full-width punctuation and
empty spaces, its name patterns, and Word's reading of its HTML: a space
between two bold or italic elements that follow each other, even an empty
one, and none at the end of an entry. Its quirks are kept, such as "ed."
after any number of editors, "Vol. 5..", "[Cited: ]" for a date accessed
with only a day, and "—." for an article whose title is the one before's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test(bibliography): keep the empty paragraphs of corpus s's APA bibliography

Word's APA style writes a paragraph for each source, empty for a source it
has nothing to write for, such as a case with no title, number, court or date.
The fixtures' generator left out empty paragraphs, so corpus s's expected
bibliography was two entries short of what the style writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in APA, as Word does

Word's APASixthEditionOfficeOnline.xsl, written in TypeScript: citations such
as "(Baker, 2010)", with the title when another source has the same first
author and initials when another first author has the same last name, and
the bibliography sorted by author, with a hanging indent.

It follows the XSL, including its quirks: the editors of a conference's
proceedings are always "Ed.", a work of art's date has no space after it
without an artist, and Word reads a space after an entry that ends in
italics, where MSXML writes a line break at the end of the copy of the
entry. Its citations and bibliographies are Word's for every source of the
four corpora Word wrote, and Word's XSL's for corpus s and for random sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in Harvard - Anglia, as Word does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in Chicago, as Word does

Ported from Word's CHICAGO.XSL, template by template, including its quirks:
a space after an entry that ends with a title in italics, as Word's XSLT
writes a line break there, "eds." left out after a list of editors, as
Word's English has none, and no space before "Edited by" after the title
of an interview. Tested against Word's own output for the probes' corpora,
and against Word's XSL for the synthetic corpus and the branches neither
reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test(bibliography): keep the empty paragraph Turabian writes for an artwork with nothing to write

Corpus s's fixture left out the paragraph Word writes for an artwork with no artist, title, institution, city or
publication title, which Turabian writes as an empty paragraph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in Turabian, as Word does

Turabian's citations are Chicago's, and it finds a source's authors and sorts its bibliography as Chicago does, so
it shares those with Chicago, from chicago-family.ts. Its entries end with where and when the source was published.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in IEEE, as Word does

Written from Word's IEEE2006OfficeOnline.xsl: citations such as "[1, p. 50]", and a
bibliography that is a table of each source's number and entry, in the order the sources are
cited. Its people are written with the style's own templates for initials, and some of its
words are English written into the style, such as "Available:".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test(bibliography): keep the empty paragraph MLA writes for an artwork with nothing to write

Corpus s's MLA fixture left out the empty paragraph Word writes for the work of art with none of its fields, as its generator dropped empty paragraphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): write citations and bibliographies in MLA, as Word does

MLA, seventh edition, written from Word's MLASeventhEditionOfficeOnline.xsl: citations such as "(Baker 50)", with the title when the authors don't tell a source apart, and a bibliography sorted by the people each source is named by, with "—" for the same people as the entry before.

It writes what Word's style writes, including where that isn't what MLA asks for: editors named first with no "eds." after several of them, an organization as a performer with no "Perf." before it, an interview's title without its italics when its interviewer follows, no space between a sound recording's album and its producer when it has neither composers nor a title, and a space after an entry that ends with italics, as Word reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix(bibliography): name the style as Word for Mac finds it, and write bibliographies' paragraphs as Word does

Word for Mac only finds a style named with a slash before its file, and opens a document with
a backslash in APA. A bibliography of no sources is Word's bold "Invalid source specified.",
and IEEE's table has an empty paragraph after it, as Word writes them when it updates the
fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* feat(bibliography): docx/bibliography, with sources, citations and bibliographies in each of Word's styles (#557)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix(bibliography): reject a style named after a property every object has

createBibliography looked the style up in an ordinary object, so a name such as "toString" or "__proto__" found an inherited value, got past the check and failed later, when the document was packed. It now checks the style is one of the definitions' own keys, and throws the documented error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix(bibliography): throw for a source whose type isn't one of SourceType's

A source with an unknown type, such as Word's own name "InternetSite" for SourceType.WEBSITE, was kept with no type and failed later in a style, with a TypeError. wordSourceOf now throws when the source is given, saying which source and type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:49:43 +01:00
DolanandClaude Opus 5.5 9397bbd549 feat: write Word's Caption style, and document captions and cross-references (#557) (#3813)
Word gives the captions it inserts the paragraph style "caption", and docx
didn't write it, so a paragraph with `style: "Caption"` came out in Normal:
Word drops a style the document doesn't define. docx now writes the style
as Word writes it when it inserts a caption (small italic text in the
theme's second dark color, with space after), and `styles.default.caption`
changes it. A Caption style in paragraphStyles or externalStyles still takes
its place.

A new docs page shows captions with SequentialIdentifier, their numbers
written by docx/layout, cross-references to them with a bookmark and
NumberedItemReference, and a table of figures, none of which the docs
covered.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 16:22:38 +01:00
Dolan ba2b4e26a0 feat: protect a document from changes in Word, with a password and editable ranges (#2271) (#3810) 2026-10-21 14:09:06 +01:00
Dolan 0132938894 feat: style a section's line numbers with styles.default.lineNumber (#551) (#3808) 2026-10-20 16:29:43 +01:00
Dolan 1bfacd5c83 fix: declare that docx needs Node.js 16 or later (#3807) 2026-10-20 14:33:39 +01:00
Dolan 9382d55176 feat: set a document's properties when patching it (#2701) (#3806) 2026-10-20 14:10:34 +01:00
Dolan 437d455034 feat: embed files in a document as OLE objects, from docx/embedded-files (#719) (#3802) 2026-10-20 12:49:44 +01:00
Dolan d71fb31dc5 feat: fit a run's text to a width with fitText (#2597) (#3801) 2026-10-20 02:55:23 +01:00
DolanandClaude Opus 5.5 3aaeff48b8 fix: start a numbered heading's table of contents entry with its number, with page numbers from docx/layout (#1130) (#3800)
* fix: start a numbered heading's table of contents entry with its number, with page numbers from docx/layout (#1130)

When Word fills in a table of contents, the entry of a numbered heading
starts with the heading's number, then a tab, with a tab stop past the
number. docx wrote the entries without the numbers. With page numbers
from docx/layout, the table is written clean, so Word shows it as it is
written and doesn't update it: the numbers were never shown. Word for
Mac opened such a document with "Main 2" where its own entry is
"1 Main 2".

A page number estimator can now work out the list numbers of the
paragraphs bookmarks start (listNumbers), which docx asks for once it
has bookmarked the headings, before it writes the entries.
estimatePageNumbers, and estimatePageNumbersWith's estimators, read
them as docx/layout numbers its lists, without laying out the pages. A
numbered heading's entry then starts with its number and a tab, or its
number and a space when its list follows the number with a space or
nothing, as Word writes it, and the pages are laid out with them. A
number docx/layout doesn't write as Word does is left out.

Word places the tab stop by its Normal template, not the document:
past the number, measured in Aptos 12 pt, by 240 twips, and 240 more a
level below the first, at the next multiple of 240 up to 1920, and
where it falls past that. docx places it the same way. The probes are
scripts/layout-probes/word-toc-numbers.ts and the documents Word saved
once it had updated their tables. After entries at levels 7 to 9, Word
places the stops after them on multiples of 200 instead, which docx
doesn't follow.

Checked in Word for Mac 16.114: Word opens the docs' example without
asking to update it, with "1 Introduction 2" to "2.1 Results 3", and
writes the same entries, tab stops and page numbers when it updates
the table itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: don't name the TOC number probes .word.docx, which the layout comparison lays out

scripts/compare-layout.sh lays out every scripts/layout-probes/*.word.docx
and compares the page of each heading with the pages Word marked in it,
failing for a committed one whose marks don't have all its pages. The
TOC number probes' documents are what Word saved once it had updated
their tables, saved before Word had laid out all their pages, and
aren't for laying out: the shape demos workflow failed on
word-toc-numbers.word.docx, "its marks have 2 of its 3 pages".

They are now word-toc-numbers.docx and word-toc-numbers-font.docx, as
the other probes' documents are named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:49:36 +01:00
Dolan f0a176ec0b fix: don't write a table row with no cells, which Word can't open (#2724) (#3799) 2026-10-19 13:02:13 +01:00
Dolan 69fc2da10d fix: stop an index entry field scrambling the document in Word (#1546) (#3792) 2026-10-19 12:23:45 +01:00
DolanandClaude Opus 5.5 ea08b9677c feat: write macro-enabled documents with VBA macros, from docx/macros (#471) (#3791)
* feat: write macro-enabled documents with VBA macros, from docx/macros (#471)

A document's macros, the macros option, make it a macro-enabled
document (.docm): its main part has the macro-enabled content type, it
has the VBA project, word/vbaProject.bin, and Packer gives it a .docm's
MIME type. The events of the document the macros handle, such as
Document_Open, are listed in word/vbaData.xml, as Word only runs the
handlers of the events listed there.

createMacros, in a new entry, docx/macros, writes the macros from VBA
code: ThisDocument's, modules and class modules. It writes the VBA
project as [MS-OVBA] describes, in a compound file ([MS-CFB]), without
a compiled cache, so Word compiles the code when it first runs it, and
lists the events ThisDocument has handlers for. A vbaProject.bin from a
.docm Word saved goes in macros too, with the events it handles.

Checked in Word for Mac 16.114: Document_Open runs when the document
opens, and so do macros in modules that use class modules and Office's
library. LibreOffice imports the modules, and the Open XML SDK validator
passes the demos for each version of Office since 2010. The demos
workflow now validates a .docm as it does a .docx.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* fix: give a character beyond U+FFFF as two ChrW in createMacros' error

createMacros' error for a character Windows-1252 doesn't have said to
write it with ChrW and its code point, such as ChrW(&H1F600) for an
emoji. ChrW only takes a UTF-16 code unit, up to &HFFFF, so that fails
in Word. The error now gives one ChrW for each code unit: the surrogate
pair, ChrW(&HD83D) & ChrW(&HDE00), which Word for Mac turns into the
emoji. The docs say so too.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say how to run the macros of a .docm downloaded in Word for Windows

The macros docs said Word asks whether to enable a .docm's macros when
it opens. Word for Windows doesn't for a file from the internet, such
as a .docm a web page made with docx and the browser downloaded: it
blocks its macros without an Enable Content button. The docs now say to
unblock the file in its Properties, that an organization's policy can
still block macros, and that Word for Mac isn't affected.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 00:13:28 +01:00
DolanandClaude Opus 5.5 7b08eacce9 fix: read an image's type from its data when it isn't given (#2952) (#3789)
TypeScript requires an ImageRun's type, but JavaScript can leave it out,
as the code in #2952 and #3305 did. The image was then written to
word/media/<hash>.undefined, which has no content type, so Word said the
document had unreadable content and Word Online wouldn't open it.

An image without a type now has it read from the bytes its data starts
with, for PNG, JPEG, GIF and BMP files, and so does an SVG image's
fallback. Data that isn't one of those is an error that says to give the
type, rather than a document Word can't read.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 21:38:46 +01:00
DolanandClaude Opus 5.5 0ffd27a95d docs: explain why TOC entries keep a heading's bold, and how to avoid it (#1369) (#3787)
When Word updates a table of contents, it copies the formatting set on a
heading's text, such as bold: true on a TextRun, onto the entry. That
takes priority over the TOC1 style, so bold: false there can't remove
it. Formatting from the heading's style isn't copied, so the fix is to
make the heading style bold instead.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:32:20 +01:00
Dolan 3b4f7777cd fix: patch a template read from a stream (#2321) (#3786) 2026-10-17 19:30:50 +01:00
Dolan 8f0a8532e4 fix: cells added below a rowSpan cell take its formatting and paragraph alignment (#1219) (#3784) 2026-10-17 16:39:04 +01:00
Dolan c08ec0ae8a feat: two lines in one and horizontal in vertical with eastAsianLayout (#1943) (#3783) 2026-10-17 15:41:30 +01:00
Dolan 65d97ee0dd docs: show how to add SVG images with a fallback (#3315) (#3782) 2026-10-17 14:15:38 +01:00
Dolan 225e8c8cbb feat: restart a numbered list with numbering.restart (#3780) 2026-10-17 11:05:57 +01:00
DolanandClaude Opus 5.5 be1b7d460a docs: point text frame users to ShapeRun text boxes (#3778)
* docs: point text frame users to ShapeRun text boxes

Text frames are positioned paragraphs (w:framePr), not the text box Word
makes when you insert one, which is a shape with text in it. The text
box page still recommended frames for most uses. Explain the difference
on the text frames page, with a floating ShapeRun example, and recommend
ShapeRun on the text box page.

Closes #866

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0121RHRfmgN8jDksNAdAWKnK

* docs: say how Google Docs shows text frames

Checked by converting a test document in Google Docs: the frame stays
in line, full width, and a floating ShapeRun text box is placed where it
should be.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0121RHRfmgN8jDksNAdAWKnK

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 23:42:07 +01:00
3bbc2d10b6 fix: restart every level of a numbering instance, not only the first (#3768)
* fix: restart every level of a numbering instance, not only the first (#2877)

* refactor: Type the numbering's level configurations, so a new instance reads them without a cast

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: Restart each level of a new list instance at the number its level is written with

A level's w:start is its start floored, or 1, so a start of 2.5 is written as 2. A new instance now starts the level at that
number too, rather than at 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: Cover a new instance of the default bullet list, which restarts only its first level

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: Give a new instance's levels out of order, so the test checks each override is of the level its `level` names

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: Say that a new list instance restarts every level, each from its own start

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 17:28:10 +01:00
DolanandClaude Opus 5.5 1fb5e15729 fix: Size rows below a merged cell with its margins, and show how to merge cells by hand (#3766)
Word makes a row below a cell merged down rows as tall as the merged
cell's margins in it, as word-merged-cell-margins.docx shows: with
rowSpan, the cells docx adds take the table's margins, so the rows below
are as tall as the table's margins above and below and a line.
docx/layout left those cells out of the row's height, and now counts
their margins.

The table docs now show merging cells by hand with verticalMerge, which
gives the merged cell's part in each row settings of its own, such as no
margins, which keeps the rows below to a line. That is what #668 asked
for besides keeping rows together.


Claude-Session: https://claude.ai/code/session_0121RHRfmgN8jDksNAdAWKnK

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 23:27:08 +01:00
Dolan 8b8f5b1083 fix: Keep merged rows together with TableRow keepNext, and indent the numbering demo's numbers (#3765) 2026-10-15 15:26:10 +01:00
DolanandClaude Opus 5.5 7f6de64474 fix: Let a table's style give its borders (#3760)
A table always wrote `w:tblBorders` with a thin single line on every side
it wasn't given, which covered the borders of its table style. A table
with a `style` now writes only the sides `borders` gives, and none
without `borders`, so the style's borders show. Tables without a style
keep their thin single borders.

Fixes #1497

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 02:43:59 +01:00
Dolan a61c85d64e feat: docx/html, HTML as a document's content (#2632) (#3752) 2026-10-13 14:53:26 +01:00
builtbysharath 677a44edd3 fix: write specVanish from its own option instead of vanish (#3746) 2026-10-12 16:33:25 +01:00
Dolan fb965994ba fix: headings in patchDocument keep their style in templates without it (#3751) 2026-10-12 15:53:25 +01:00
Dolan f5b7cea8bc fix: numbered and bulleted paragraphs in patchDocument (#3750) 2026-10-12 14:08:59 +01:00
Dolan 7826217f8d docs: fix mistakes found while answering discussions (#3748) 2026-10-12 13:42:45 +01:00
DolanandClaude Opus 5.5 b53aca8a3d docs: explain that only header rows at the top of a table repeat (#3745)
Word repeats a table's first row and the rows straight after it that set
tableHeader, and ignores tableHeader on rows further down. Document this,
and show how to give each part of a long table its own repeating header
by making each part a table of its own.

Closes #2425

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 13:36:50 +01:00
b40cf4940d feat(fonts): embed the bold and italic faces of a font (#3736)
* feat(fonts): embed the bold and italic faces of a font

FontOptions takes optional bold, italic and boldItalic files beside
data, the regular face. Each face is embedded as a file of its own,
with its own relationship and key, and the font table refers to it
with w:embedBold, w:embedItalic or w:embedBoldItalic. docx/layout
measures text in a face from that face's file.

* docs(fonts): make the bold and italic faces example live

Embed the four faces of Crimson Text (OFL, licence included) from
demo/assets so the example runs in the docs, and show a run in each
face. Mark FontWrapper.fontOptionsWithKey deprecated in favour of files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:00:22 +01:00
vhinayindiaandvhinayindia 46494c5363 docs: explain placeholder discovery before building patches (#3713)
* docs: explain placeholder discovery before building patches

* docs: clarify placeholder detector delimiter support

---------

Co-authored-by: vhinayindia <281186805+vhinayindia@users.noreply.github.com>
2026-10-07 00:36:56 +01:00
Alex Casillas a0e2756524 fix: make frame width and height optional (#3717) 2026-10-07 00:36:45 +01:00
Dolan 31b98f2e62 feat(layout): lay out compatibility modes, suppressTopSpacing, useFELayout, booklets and HTML divisions where round 26 shows Word's way, as Word does (#3730)
Word's PDFs of round 26 settled what word-stops-compat3, word-stops-top-spacing3 and -4, word-stops-booklet3, word-stops-divisions2 and word-stops-fe-layout3 probed. In Word 2010's and 2007's modes a table of a share of the width is that share of the text and its margins, a table widened for a long word grows to the room with the margins, floating tables sized to their text shift as CN9's did, text after a tab past the end goes on to 22 inches, and gaps of 1250 twips or less beside a frame are left empty; in Word 2007's mode East Asian text in its language breaks as in none and VML shapes' outlines take no room. suppressTopSpacing leaves 0.8 lines and bordered paragraphs' later lines as they are, reverse-folded booklets are the section's pages, a division's box is drawn once with its later paragraphs taking its margins and side borders, and useFELayout puts half the font's average character width between East Asian text and Latin letters or digits.
2026-10-06 22:30:48 +01:00
Dolan 22d15122e5 feat(layout): lay out bordered and Word 6 list numbers, hidden marks at sections, controls, headers and notes, and deleted rows and section breaks, as round 26 shows Word does (#3728)
* feat(layout): lay out bordered and Word 6 list numbers, the schema's other alignments, lists of one definition, hidden marks at sections, controls, headers and notes, and deleted rows and section breaks where round 26 shows Word's way, as Word does

* fix(layout): keep the section break of the paragraph a hidden mark joins to, as the next one's mark is the joined paragraph's
2026-10-06 21:47:10 +01:00
Dolan a1215475f7 feat(layout): lay out Japanese line rules, compressed punctuation, grid indents, right-to-left line ends, endnotes down the page and Arabic's letters side by side where round 26 shows Word's way, as Word does (#3726)
* feat(layout): lay out Japanese line rules, compressed punctuation, grid indents, right-to-left line ends, endnotes down the page and Arabic's letters side by side where round 26 shows Word's way, as Word does

Word's PDFs of round 26 (word-stops-east-asian3.ts and word-stops-arabic2.ts) show that Word's strict rules keep each small kana and the prolonged sound mark from the start of a line of Japanese, in place of the document's own list, and change nothing in Chinese or Korean; that compressed punctuation leaves justified Japanese and left-aligned Chinese as they are; that indents of part of a cell on a grid that snaps to characters are rounded up line by line, before the margin too, with tabs to their stops; that the space after a line's last right-to-left word takes room beside left-to-right text in a right-to-left run and between right-to-left words in any run; that endnotes after text that runs down the page run down it, and end with their section before text that runs another way; and that Word doesn't kern Arabic's letters in Arial and Times New Roman, every pair being as wide as its forms to 8 thousandths of an em. The layout follows each, and keeps a narrowed stop where a case is still open: half-width small katakana and the document's own lists beyond the strict list, distributed Japanese and justified or distributed Chinese and Korean with compression, indents a character or more before the margin, endnotes from a section followed by one that runs as it does before a change of direction, and Calibri's Arabic, which Word kerns by pairs of glyphs.

* docs: say Word doesn't kern Arabic's letters side by side in the fonts of the tables, and spell tatweels

The fonts paragraph of docs/usage/layout.md still said Word kerns them in Arial, Times New Roman and Cambria by pairs not yet known, so only Courier New's Arabic is laid out, which round 26's AR4 PDF showed to be wrong, and the probe README's ignore list lacked tatweels, which failed CSpell.

* fix: fail the Arabic kerning reader on a PDF without its probe, or a paragraph without its 42 words

Otherwise a PDF with no AR4 labels wrote {} and exited 0, and the checker reported nothing.

* fix(layout): measure Arabic's letters in their joined forms as drawn too, with ligatures or kerning on

measureTextWidthAsDrawn measured each Arabic letter in its isolated form where measureTextWidth has the forms the letters beside them join them in, so a word of Arabic in Arial with ligatures on, which no longer stops, was nearly twice as wide as Word draws it. It now takes the joined widths by each glyph's index among the characters, as the plain measurement does.
2026-10-06 21:30:57 +01:00