bun-docx 0.16.0 → 0.18.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 +27 -6
- package/dist/index.js +2366 -690
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -184,17 +184,19 @@ docx edit FILE --at LOCATOR <content> # LOCATOR = pN | pN:S-
|
|
|
184
184
|
docx delete FILE --at LOCATOR # LOCATOR = pN | pN-pM | tN | sN | tN:rRcC:pK (cell paragraph)
|
|
185
185
|
docx sections FILE [--at LOCATOR] [--columns N] [--type T] [--orientation O] [--size SIZE] [--margins M] # LOCATOR = pN-pM | pN (wrap a range in N columns) | sN (edit one section's columns/type/page geometry). Multi-column layout AND page setup live HERE. PAGE GEOMETRY (margins/orientation/size) with NO --at applies to the WHOLE document (every section); --at sN targets one. Columns/type need --at.
|
|
186
186
|
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
|
|
187
|
-
docx replace FILE PATTERN REPLACEMENT [--regex] [--ignore-case] [--all] [--limit N] [--current | --baseline] [--exact] [--track] [--dry-run]
|
|
187
|
+
docx replace FILE PATTERN REPLACEMENT [--at pN] [--regex] [--ignore-case] [--all] [--limit N] [--current | --baseline] [--exact] [--track] [--dry-run]
|
|
188
188
|
# Keeps the run's formatting (bold/font) and any tabs — the no-rebuild way to fill a
|
|
189
189
|
# formatted/tabbed template line (e.g. "**Org Name**⇥Date"); don't hand-build --runs to refill it.
|
|
190
|
-
#
|
|
190
|
+
# --at pN (or a cell paragraph tT:rRcC:pN) CONFINES the replace to one paragraph — use it when the
|
|
191
|
+
# SAME placeholder repeats across the doc (a résumé's "City, State" in every entry) and you want THE
|
|
192
|
+
# one in a specific paragraph, instead of find → edit --at pN:S-E span surgery. Batch entries take "at" too.
|
|
191
193
|
|
|
192
194
|
# Batch — apply many changes from ONE read (no re-reading between edits). Keys
|
|
193
195
|
# on each JSONL line mirror the command's flags; all locators address the doc as
|
|
194
196
|
# read. insert/edit also accept --batch - to read JSONL from stdin.
|
|
195
197
|
docx edit FILE --batch fills.jsonl # { at, <one of: text|clear|markdown|runs|code|task>, style?, … }
|
|
196
198
|
docx insert FILE --batch additions.jsonl # { after|before, <content>, style?, color?, … }
|
|
197
|
-
docx replace FILE --batch script.jsonl # { pattern, replacement, regex?, all?, limit?, … } applied in order
|
|
199
|
+
docx replace FILE --batch script.jsonl # { pattern, replacement, at?, regex?, all?, limit?, … } applied in order ("at" scopes that entry to one paragraph)
|
|
198
200
|
docx delete FILE --batch drop.jsonl # { at } per line — whole blocks (pN/tN/cell), resolved live-first
|
|
199
201
|
|
|
200
202
|
# All four of insert/edit/delete/replace accept --track to record that one
|
|
@@ -281,16 +283,33 @@ docx tables set-widths FILE --at tN --widths "25%,25%,50%" | "1440,..." | aut
|
|
|
281
283
|
docx tables merge FILE --at tN:rR1cC1-rR2cC2
|
|
282
284
|
docx tables unmerge FILE --at tN:rRcC
|
|
283
285
|
docx tables borders FILE --at tN [--style single|double|none] [--size N] [--color HEX]
|
|
286
|
+
docx tables format FILE --at LOCATOR [--shade HEX|NAME] [--valign top|center|bottom]
|
|
287
|
+
[--halign left|center|right|justify] [--cell-borders SIDES]
|
|
288
|
+
[--align left|center|right] [--style ID] [--row-height M] [--repeat-header]
|
|
289
|
+
|
|
290
|
+
docx lists set FILE --at pN [--start N] [--format FMT] [--restart] [--continue]
|
|
291
|
+
# renumber a NUMBERED list (--at = any item; applies to the whole list).
|
|
292
|
+
# FMT = decimal | lower-alpha | upper-alpha | lower-roman | upper-roman.
|
|
293
|
+
# --restart splits a fresh list off here; --continue picks up the previous
|
|
294
|
+
# list's numbering instead of restarting. Untracked (Word records no revision).
|
|
284
295
|
|
|
285
296
|
docx track-changes on|off FILE
|
|
297
|
+
docx track-changes list FILE [--json]
|
|
286
298
|
docx track-changes accept FILE (--at tcN [--at tcM ...] | --at revN | --all)
|
|
287
299
|
docx track-changes reject FILE (--at tcN [--at tcM ...] | --at revN | --all)
|
|
288
|
-
|
|
289
|
-
#
|
|
300
|
+
docx track-changes apply FILE [--accept H ...] [--reject H ...]
|
|
301
|
+
# `list` defaults to a text table, one LOGICAL change per line (revN collapses a del+ins
|
|
302
|
+
# pair onto one line); `--json` for the raw array. A del+ins REPLACE pair shares a
|
|
303
|
+
# "group": "revN"; `--at revN` accepts/rejects both halves in one call.
|
|
304
|
+
# To FINALIZE a review (accept some, reject the rest), use `apply` — it takes both decision
|
|
305
|
+
# lists in ONE call, resolved against the original ids, so nothing renumbers mid-operation
|
|
306
|
+
# and the file is never left half-finalized. Doing it as separate accept then reject calls
|
|
307
|
+
# renumbers the ids between them. After a subset accept/reject/apply, the confirmation
|
|
308
|
+
# re-lists what remains with its renumbered handles.
|
|
290
309
|
```
|
|
291
310
|
|
|
292
311
|
> **One rule to memorize: addressing an existing thing is always `--at`.**
|
|
293
|
-
> `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
|
|
312
|
+
> `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` (and `replace` accepts an optional `--at pN` to *confine* the substitution to one paragraph). `images extract --to DIR` is an *output directory*, not a locator.
|
|
294
313
|
|
|
295
314
|
## Output contract
|
|
296
315
|
|
|
@@ -420,6 +439,8 @@ docx track-changes accept doc.docx --at tc0 --at tc2 # or --all
|
|
|
420
439
|
|
|
421
440
|
**Edit & create styles.** `docx styles set FILE --at Heading1 --color 1F4E79 --size 16 --bold` rewrites the *style definition* in `word/styles.xml`, so every paragraph or run that uses the style picks up the change at once ("make all Heading 1s green") — the same run-/paragraph-formatting flags as `edit` (color/font/size/highlight/underline/caps + alignment/spacing/indentation for paragraph styles). `docx styles create FILE Callout --color C00000 --bold` mints a new paragraph or character style that `insert/edit --style Callout` can then apply. Editing an un-materialized built-in (`--at Heading3` on a doc that never used it) provisions it first; a paragraph with its own *direct* formatting keeps it (the override wins — the definition edit never touches the body). Style edits are **not** tracked changes even under track-changes — matching Word, which applies style-definition edits to `styles.xml` directly with no redline.
|
|
422
441
|
|
|
442
|
+
**List numbering.** `docx lists set FILE --at p12 --start 5` makes a numbered list begin at 5; `--format upper-roman` (or `lower-alpha`/`upper-alpha`/`lower-roman`) switches the glyph; `--restart` splits a fresh list off at that item; `--continue` makes a list pick up the previous list's numbering instead of restarting. `--at` names any item — the change applies to the whole list. The start round-trips through the markdown ordinal (the body reads `5. 6. 7.`); the glyph and any continue link, which GFM can't express, surface as a deviation-only `<!-- docx:list p12 format="upper-roman" -->` / `<!-- docx:list p20 continues -->` hint (dropped on import, like every `docx:` note — `read --ast` carries `list.start`/`list.format` losslessly). Untracked, matching Word, which records no revision for a list-numbering change.
|
|
443
|
+
|
|
423
444
|
**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.
|
|
424
445
|
|
|
425
446
|
**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.
|