bun-docx 0.5.0 → 0.6.1
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 +44 -4
- package/dist/index.js +950 -107
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ bunx bun-docx read doc.docx
|
|
|
31
31
|
|
|
32
32
|
```sh
|
|
33
33
|
docx create FILE [--title T] [--author A] [--text "..."]
|
|
34
|
-
docx read FILE
|
|
34
|
+
docx read FILE [--markdown [--from pN] [--to pN] [--changes] [--comments]]
|
|
35
35
|
docx insert FILE --after p3 --text "..." [--style HeadingN] [--color HEX] [--bold] [--italic] [--url URL]
|
|
36
36
|
docx insert FILE --after p3 --runs '[{"type":"text","text":"X","bold":true}]'
|
|
37
37
|
docx edit FILE --at p3 --text "..." | --runs '[...]'
|
|
@@ -40,6 +40,9 @@ docx delete FILE --at p3
|
|
|
40
40
|
docx find FILE QUERY [--regex] [--ignore-case] [--all] [--nth N]
|
|
41
41
|
docx replace FILE PATTERN REPLACEMENT [--regex] [--ignore-case] [--all] [--limit N] [--dry-run]
|
|
42
42
|
|
|
43
|
+
docx wc FILE [LOCATOR]
|
|
44
|
+
docx outline FILE
|
|
45
|
+
|
|
43
46
|
docx comments add FILE --range p3:5-20 --text "..." [--author NAME]
|
|
44
47
|
docx comments reply FILE --to c0 --text "..."
|
|
45
48
|
docx comments resolve FILE --id c0 [--unset]
|
|
@@ -62,7 +65,40 @@ docx info locators [--json]
|
|
|
62
65
|
|
|
63
66
|
Every command has `--help`. Mutating commands accept `--dry-run` and `-o/--output PATH` (write to a parallel file instead of overwriting `FILE`). JSON output by default for `read` and `*.list`; structured `{ok, code, error, hint}` on failure.
|
|
64
67
|
|
|
65
|
-
When `<w:trackChanges/>` is set in the doc (toggle via `docx track-changes FILE on`), `insert`/`edit`/`delete`/`replace` automatically emit `<w:ins>`/`<w:del>` markers
|
|
68
|
+
When `<w:trackChanges/>` is set in the doc (toggle via `docx track-changes FILE on`), `insert`/`edit`/`delete`/`replace` automatically emit `<w:ins>`/`<w:del>` markers. Author resolution: per-call `--author NAME` overrides `$DOCX_AUTHOR`, which falls back to `docx-cli`. To make a one-off untracked edit, flip the flag off, edit, then flip it back on. `find` results inside tracked-change wrappers carry a `trackedChanges` array so agents can decide what to do with hits in pending insertions/deletions.
|
|
69
|
+
|
|
70
|
+
OOXML has no native tracked-change form for hyperlink edits or image swaps, so when track-changes is on, `hyperlinks add/replace/delete` and `images replace` auto-emit a `[docx-cli] …` comment anchored to the affected span/run instead. The comment carries the same `--author` attribution as the other tracked operations. Word itself silently bypasses tracking for these — we trade silence for an explicit audit trail.
|
|
71
|
+
|
|
72
|
+
### Markdown rendering
|
|
73
|
+
|
|
74
|
+
`docx read FILE --markdown` renders the document body as GitHub-flavored Markdown instead of JSON. Useful when you (or an LLM) want to skim a doc quickly without parsing the AST. Each rendered paragraph is followed by an HTML comment with its locator (`<!-- p3 -->`) so the markdown is invisible-pinned: humans see clean prose in a renderer, agents parse the locators from raw text.
|
|
75
|
+
|
|
76
|
+
- Headings → `#`/`##`/`###` based on `style="HeadingN"`
|
|
77
|
+
- Lists → `- ` indented per `level`
|
|
78
|
+
- Bold/italic/strike → `**…**` / `*…*` / `~~…~~`; underline → `<u>…</u>`
|
|
79
|
+
- Run color → `<span style="color:#hex">…</span>`; highlight → `<span style="background-color:NAME">…</span>`
|
|
80
|
+
- Hyperlinks → `[text](url)`
|
|
81
|
+
- Images → ``
|
|
82
|
+
- Tables → GitHub pipe tables; multi-paragraph cells joined with `<br>`; per-cell-paragraph locators inline
|
|
83
|
+
- Section breaks → `---`
|
|
84
|
+
- Equations (`<m:oMath>`/`<m:oMathPara>`) → `` `equation: text` `` (concatenated `<m:t>` plaintext; structure like sub/sup/fractions collapses to literal characters — degraded but readable)
|
|
85
|
+
- Footnotes / endnotes → inline `[^fnN]` / `[^enN]` refs with GFM footnote definitions at end of output
|
|
86
|
+
- Charts / SmartArt / shapes / other non-picture drawings → `` `[chart]` `` / `` `[smartart]` `` / `` `[shape]` `` / `` `[drawing]` `` placeholders
|
|
87
|
+
|
|
88
|
+
`--from LOC` and `--to LOC` slice by top-level block (both inclusive). Accepts paragraph, table, cell, span, and range locators; cell/span/range collapse to their enclosing top-level block. Comment/image/hyperlink locators are rejected.
|
|
89
|
+
|
|
90
|
+
`--changes` renders tracked insertions and deletions as `<ins>`/`<del>` instead of producing the accepted view (which silently drops deletions and inlines insertions).
|
|
91
|
+
|
|
92
|
+
`--comments` appends a GFM footnote reference (`[^cN]`) at the end of each commented span and emits one footnote definition per comment at the end of the output:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
… some commented text[^c0] …
|
|
96
|
+
|
|
97
|
+
[^c0]: "commented span" — Author Name (2024-01-15T...): comment body
|
|
98
|
+
[^c1]: "another span" — Author Name (2024-01-15T...) ↳ c0: reply body
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Footnotes/endnotes (the document's own `<w:footnoteReference>` / `<w:endnoteReference>`) are rendered unconditionally — `[^fn1]` / `[^en1]` inline + `[^fn1]: body` definitions at the end of the output, alongside any `--comments` footnotes. They use `fn`/`en` prefixes so the namespaces don't collide.
|
|
66
102
|
|
|
67
103
|
### Locators
|
|
68
104
|
|
|
@@ -104,10 +140,14 @@ src/
|
|
|
104
140
|
help.ts # top-level --help
|
|
105
141
|
respond.ts # JSON ack / structured error helpers
|
|
106
142
|
create/ # create FILE
|
|
107
|
-
read/ # read FILE
|
|
143
|
+
read/ # read FILE [--markdown ...] (markdown.ts renderer)
|
|
108
144
|
insert/ # insert FILE (uses ./emit Paragraph component)
|
|
109
145
|
edit/ # edit FILE
|
|
110
146
|
delete/ # delete FILE
|
|
147
|
+
find/ # find FILE QUERY
|
|
148
|
+
replace/ # replace FILE PATTERN REPLACEMENT
|
|
149
|
+
wc/ # wc FILE [LOCATOR]
|
|
150
|
+
outline/ # outline FILE
|
|
111
151
|
comments/ # add | reply | resolve | delete | list
|
|
112
152
|
images/ # list | extract | replace
|
|
113
153
|
hyperlinks/ # add | list | replace | delete
|
|
@@ -117,7 +157,7 @@ src/
|
|
|
117
157
|
package/ # JSZip open/close, named-part read/write
|
|
118
158
|
parser/ # XmlNode class + parse/serialize + JSX factory
|
|
119
159
|
jsx/ # h, Fragment, namespaces (w, r, a, wp, pic, ...)
|
|
120
|
-
ast/ # types + DocView + XML→AST reader
|
|
160
|
+
ast/ # types + DocView + XML→AST reader (text.ts: shared paragraph helpers)
|
|
121
161
|
locators/ # parse "p3:5-20" + resolve to refs
|
|
122
162
|
tests/
|
|
123
163
|
core/, cli/, integration/
|