bun-docx 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/dist/index.js +1099 -346
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,7 @@ docx find FILE (--highlight COLOR|any | --color HEX | --bold | --italic | --u
|
|
|
89
89
|
docx wc FILE [LOCATOR] [--accepted | --baseline | --current] [--json]
|
|
90
90
|
docx outline FILE [--style-prefix S] [--json]
|
|
91
91
|
docx styles FILE [--used] [--at STYLEID] [--json] # the style catalog (not in the body) — what --style NAMEs exist
|
|
92
|
+
docx styles --catalog [--json] # built-in styles you can apply on demand (Title, Heading1–9, Quote, …), no FILE needed
|
|
92
93
|
docx render FILE [--out DIR] [--engine word|libreoffice|auto] [--dpi N] [--pages 1-N] [--format png|jpg]
|
|
93
94
|
|
|
94
95
|
docx comments list FILE [--include-resolved] [--thread cN]
|
|
@@ -133,11 +134,13 @@ clean):
|
|
|
133
134
|
### Mutate (change FILE in place; `--dry-run`, `-v` everywhere; `-o PATH` on every mutator except `create`, whose positional FILE is already the output)
|
|
134
135
|
|
|
135
136
|
```sh
|
|
136
|
-
docx create FILE [--title T] [--author A] [--text "..." | --from PATH.md | --from -] [--force]
|
|
137
|
+
docx create FILE [--title T] [--author A] [--text "..." | --text-file PATH | --from PATH.md | --from -] [--force]
|
|
137
138
|
docx insert FILE (--after | --before) LOCATOR <content> # LOCATOR = pN | tN | sN | tN:rRcC:pK
|
|
139
|
+
docx insert FILE (--at-start | --at-end) <content> # no locator — prepend / append to the document
|
|
138
140
|
docx edit FILE --at LOCATOR <content> # LOCATOR = pN | pN:S-E | pN-pM | sN | eqN | tN:rRcC:pK[:S-E]
|
|
139
141
|
docx delete FILE --at LOCATOR # LOCATOR = pN | pN-pM | tN | sN
|
|
140
142
|
docx sections FILE --at LOCATOR --columns N [--type T] # LOCATOR = pN-pM | pN (wrap a range in N columns) | sN (recount an existing section). Multi-column layout lives HERE, not in insert.
|
|
143
|
+
docx styles set-default-font FILE "Font Name" [--size N] [--all] # document-wide font: sets styles.xml docDefaults + theme major/minor; --all also repoints styles/runs that pin their own font
|
|
141
144
|
docx replace FILE PATTERN REPLACEMENT [--regex] [--ignore-case] [--all] [--limit N] [--current | --baseline] [--exact] [--track] [--dry-run]
|
|
142
145
|
|
|
143
146
|
# Batch — apply many changes from ONE read (no re-reading between edits). Keys
|
|
@@ -161,6 +164,8 @@ docx delete FILE --batch drop.jsonl # { at } per line — whole blocks (
|
|
|
161
164
|
# edit --text "" rejected (it would leave an invisible blank paragraph) — use `delete` to remove the
|
|
162
165
|
# line, or `--runs '[]'` to blank it but keep an empty spacer.
|
|
163
166
|
# --runs '[{"type":"text","text":"X","bold":true}]'
|
|
167
|
+
# --text-file PATH # (insert/create) LITERAL multi-paragraph text, NOT parsed — every char verbatim,
|
|
168
|
+
# each newline = a new paragraph. For prose GFM would corrupt: "3. note" stays "3.", *x* / [t](u) / bare URLs / {++x++} untouched.
|
|
164
169
|
# --markdown "..." | --markdown-file PATH # GFM + math + CriticMarkup + inline HTML formatting → blocks
|
|
165
170
|
# --code "..." | --code-file PATH [--language LANG]
|
|
166
171
|
# --equation "x^2 + y^2" [--display] (insert; edit also accepts --inline)
|
|
@@ -210,7 +215,7 @@ docx track-changes reject FILE (--at tcN [--at tcM ...] | --at revN | --all)
|
|
|
210
215
|
```
|
|
211
216
|
|
|
212
217
|
> **One rule to memorize: addressing an existing thing is always `--at`.**
|
|
213
|
-
> `comments reply/resolve/delete`, `footnotes/endnotes edit/delete`, `images extract/replace/delete`, `hyperlinks replace/delete`, `tables *`, `track-changes accept/reject`, `edit`, and `delete` all take `--at LOCATOR`. The exceptions are positional or directional by nature: `insert` uses `--after`/`--before LOCATOR
|
|
218
|
+
> `comments reply/resolve/delete`, `footnotes/endnotes edit/delete`, `images extract/replace/delete`, `hyperlinks replace/delete`, `tables *`, `track-changes accept/reject`, `edit`, and `delete` all take `--at LOCATOR`. The exceptions are positional or directional by nature: `insert` uses `--after`/`--before LOCATOR` (or `--at-start`/`--at-end` for the document boundaries, no locator); `read` slices with `--from`/`--to LOCATOR`; `wc` takes a positional `[LOCATOR]`; `find`/`replace` take a positional `QUERY`/`PATTERN`. `images extract --to DIR` is an *output directory*, not a locator.
|
|
214
219
|
|
|
215
220
|
## Output contract
|
|
216
221
|
|
|
@@ -333,6 +338,10 @@ docx track-changes accept doc.docx --at tc0 --at tc2 # or --all
|
|
|
333
338
|
|
|
334
339
|
**Markdown dialect.** `create --from`, `insert/edit --markdown`, and the note bodies all parse the same GFM + math + CriticMarkup + inline-HTML-formatting dialect (remark + remark-gfm + remark-math + an in-house inline-surgery transform), composing the existing OOXML emitters. `read` emits a compatible dialect, so the read → edit → write loop round-trips (lossless for paragraphs, lists, and nested blockquotes; code/tables/math/headings inside a blockquote intentionally escape to top level on import). `read --ast` is the fully lossless JSON form.
|
|
335
340
|
|
|
341
|
+
**Literal text — the parser-free channel.** When you want prose inserted *exactly* — reviewer notes, quoted excerpts, anything where Markdown would misfire — use `create --text-file PATH` / `insert --text-file PATH` (or `-` for stdin). Every character lands verbatim and each newline starts a new paragraph; nothing is interpreted, so `3. note` stays `3.` (no ordered-list renumber), and `*x*`, `[t](u)`, bare URLs, and `{++x++}` are kept as written. This exists because GFM corruption isn't always escapable: bare URLs autolink with no escape sequence at all, and CriticMarkup eats `{++…++}` regardless of backslashes — so a literal path is the only safe way to author untouched prose.
|
|
342
|
+
|
|
343
|
+
**Document-wide font.** `docx styles set-default-font FILE "Times New Roman"` sets the font in the two places a font actually lives — `word/styles.xml` `<w:docDefaults>` (the formal default) *and* the theme font scheme (`word/theme/theme1.xml`, major + minor `<a:latin>`), since real Word docs resolve their fonts *through* the theme and touching only one silently loses to the other. Body text and theme-following headings both adopt it; styles or runs that pin their own font (a code block's monospace, a deliberately-Arial run) are preserved and named in the ack, with `--all` to repoint even those. `--size N` sets the default size on the same write.
|
|
344
|
+
|
|
336
345
|
**Run formatting beyond bold/italic.** Properties markdown has no native syntax for — text color, theme color, highlight, shading, underline (all 18 styles + color), super/subscript, small/all caps, font, and size — are emitted as the **HTML a markdown reader actually renders**, so the output looks right in GitHub, VS Code, Obsidian, and browsers (Pandoc `[text]{…}` spans render as literal brackets in all of those). `read` emits semantic tags where they exist — `<mark>overdue</mark>`, `<sup>x</sup>`, `<sub>2</sub>` — a `<span style="color:#C00000">…</span>` for the CSS-expressible properties, and `data-*` attributes for the OOXML-only ones CSS can't express (theme colors, underline styles); `insert/edit --markdown` parses them back losslessly, and a leading `<!-- docx:base font="Arial" size="8pt" -->` note declares the document's dominant font/size once so the body isn't buried in per-run repetition. Bold/italic/strike/code/links stay native (`**`/`*`/`~~`/`` ` ``/`[](…)`). Because the inline-surgery transform scans whole sibling sequences, a CriticMarkup marker or span can straddle other formatting — `{++**bold insertion**++}` is tracked correctly. An invalid enum value (e.g. a bogus highlight name) fails with a clear error rather than silently vanishing. Inserted plain content inherits the surrounding paragraph's font/size so it blends in.
|
|
337
346
|
|
|
338
347
|
**Visual verification.** `docx render` is the only command that needs an external runtime: it drives Microsoft Word (macOS via `osascript`, Windows via PowerShell COM — the ground-truth renderer) or LibreOffice (`soffice`, cross-platform) to produce a PDF, then rasterizes in-process via the bundled `@hyzyla/pdfium` WASM package — no poppler/pdftoppm/ImageMagick needed. Agents that consume PNGs use this to verify edits, diff accept/reject before-vs-after, or generate screenshots.
|