Commit Graph
5 Commits
Author SHA1 Message Date
Dolan a61c85d64e feat: docx/html, HTML as a document's content (#2632) (#3752) 2026-10-13 14:53:26 +01:00
DolanandClaude Opus 5.5 7678105585 feat: footnotes and endnotes in patchDocument (#3589)
* feat: footnotes and endnotes in patchDocument

patchDocument takes footnotes and endnotes, shaped as in a Document, for the
notes that patches refer to with a FootnoteReferenceRun or an
EndnoteReferenceRun. Before, a patch could insert a reference but not the note,
so the document pointed at a footnote that didn't exist.

Each reference a patch inserts gets a note of its own, with an id that none of
the template's notes have. Only the notes that are referred to are written. A
template without notes is given the part, its relationship and content type,
and the note styles it's missing.

Closes #3113

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

* test: escape the dots in the relationship types the notes tests match

CodeQL flagged a regular expression built from a relationship type's URL,
whose dots matched any character.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:36:37 +01:00
DolanandClaude Opus 5.5 c169dd1a83 feat: live examples in the docs, which run, draw the document next to the code, and can be edited and downloaded (#3556)
* feat: live examples in the docs, which run, draw the document next to the code, and can be edited and downloaded

The docs' code examples were plain snippets, often fragments that couldn't run. A code block marked ```ts live is now
an example readers can see and change: the page runs it with docx, draws the document it makes next to the code with
docx-preview, and offers the .docx to download. Clicking the code opens an editor (Monaco) that knows docx's types,
the pages are drawn again as the code changes, and View closes the editor. Split, Code and Preview show the code and
the pages side by side, or one of them. The demos a page includes are live too.

Every example in the docs that builds or patches a document is now live: 443 of them, each a whole file with its
imports, so it runs as written. Code about other things, such as installing, bundlers or servers, stays plain.

Running them showed docs that were wrong, fixed here:
- Landscape: docx swaps a landscape page's width and height itself, so the docs' swapped sizes made a tall page
  marked as landscape
- Comments: `comments.children` takes plain objects, not `new Comment(...)`
- Custom properties are text only
- APIs that no longer exist: MathText, Row, `.then` on Packer.toStream, patchDocument(buffer, ...),
  createParagraph().heading1(), a border's `value`, TextRun's `.break()`
- The templates and patcher examples read files that aren't in the repository. They now patch the templates in
  demo/assets, or make their own

`npm run build.docs` copies docx's browser builds into docs/live-examples/lib, so the docs use the docx they
describe, and the Pages workflow runs it. The folder is gitignored, and cspell and ESLint skip it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

* docs: the bullet examples draw a bullet, and the patcher's usage writes the patched document

"ὠ" is U+1F60, a Greek omega, since \u takes four hex digits, so the two live bullet examples on
the numbering page drew it as each item's bullet. They use "•" now. The patcher's usage example
now awaits patchDocument and writes the document it makes, as the example after it does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 13:00:29 +01:00
DolanandClaude Opus 5.5 e0ff13ee3d chore: organise the demos into a folder for each topic (#3552)
* chore: organise the demos into a folder for each topic

The demos were one flat list of 124 numbered files, which made it hard to
find the one you wanted. Each is now in a folder for its topic, such as
demo/tables/basic-table.ts, with a name that says what it shows instead of
a number.

npm run demo lists every demo and narrows the list as you type. It also
takes a demo's path or name, a topic, or search words.

The demos' images moved to demo/assets/images, as images is now a topic.
The docs' links, the Demos workflow, the shape render script and its
reference images use the new paths and names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

* fix: list only a topic's own demos, and drop stale output file names

npm run demo text also offered the text-boxes demos and others with
"text" in their name, so a topic now searches for "text/". Three demos
logged their old numbered file name after writing My Document.docx.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 01:40:45 +01:00
Dolanandmatt b44ac388df feat: add endnotes support to docx library (#3354)
* feat: add endnotes support to docx library

- Add comprehensive endnotes implementation with EndnoteReferenceRun component
- Create Endnotes class and EndnotesWrapper for document integration
- Add endnote attributes, reference runs, and separator components
- Update documentation to cover both footnotes and endnotes usage
- Include demo file demonstrating endnotes functionality with multiple sections
- Integrate endnotes into compiler pipeline and content types
- Add comprehensive test coverage for endnote components

Endnotes appear at the end of the document, unlike footnotes which appear at the bottom of each page, making them ideal for academic papers and formal documents.

🤖 Generated with [Claude Code](https://claude.ai/code)

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

# Conflicts:
#	src/export/packer/next-compiler.ts
#	src/file/paragraph/run/empty-children.ts
#	src/file/styles/style/default-styles.ts

* Fix tests

* Add documentation

* Add and fix test

---------

Co-authored-by: matt <matthew.ed.keller@gmail.com>
2026-02-16 00:12:28 +00:00