@v1hz/md2docx 2.5.0 → 2.6.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
CHANGED
|
@@ -26,11 +26,16 @@
|
|
|
26
26
|
| 图片尺寸限制 | 按自然尺寸等比缩小超过最大宽度或高度的图片 |
|
|
27
27
|
| Mermaid 图表 | 使用 beautiful-mermaid 和 resvg-wasm 将 Mermaid 渲染为高 DPI PNG |
|
|
28
28
|
| Word 样式 | 支持受控语义化配置和完整底层样式,也可从现有 DOCX 提取样式 |
|
|
29
|
+
| 配置预设 | 将处理配置和两层 Word 样式保存为可切换、可继承默认值的预设 |
|
|
29
30
|
| Markdown 格式化 | 可只运行预处理流水线,输出格式化后的 Markdown |
|
|
30
31
|
| 去除分隔符 | 默认移除 `---`、`***`、`___` 等分隔符行,减少无用页面间距 |
|
|
31
32
|
| 集中缓存 | 中间文件统一存储到 `~/.md2docx/`,不会在当前目录创建 `tmp/` |
|
|
32
33
|
| Node 与可执行版本 | 支持 npm CLI,也支持构建不依赖 Node.js/Bun 的 Windows 可执行文件 |
|
|
33
34
|
|
|
35
|
+
## AI 辅助
|
|
36
|
+
|
|
37
|
+
本仓库提供 [`SKILL.md`](SKILL.md),是供 AI 代码助手(如 Zed、Cursor、GitHub Copilot)使用的技能描述文件。在 AI 对话中引用此文件,AI 就能正确使用 `md2docx` CLI 完成转换、格式化、样式定制和导出等操作。
|
|
38
|
+
|
|
34
39
|
## 安装方式
|
|
35
40
|
|
|
36
41
|
### npm CLI
|
|
@@ -64,6 +69,10 @@ md2docx --file report.md --output output/report.docx
|
|
|
64
69
|
# 使用自定义配置、底层样式和语义化样式配置
|
|
65
70
|
md2docx -f report.md -c config.json --style-raw style-raw.json --style-config style-config.json
|
|
66
71
|
|
|
72
|
+
# 保存并使用预设
|
|
73
|
+
md2docx preset save --name academic --config config.json --style-config style-config.json
|
|
74
|
+
md2docx preset use academic
|
|
75
|
+
|
|
67
76
|
# 只执行 Markdown 预处理
|
|
68
77
|
md2docx format -f report.md
|
|
69
78
|
|
|
@@ -90,6 +99,9 @@ md2docx format -f <markdown> [选项]
|
|
|
90
99
|
md2docx export config [选项]
|
|
91
100
|
md2docx export style-raw [选项]
|
|
92
101
|
md2docx export style-config [选项]
|
|
102
|
+
md2docx preset list
|
|
103
|
+
md2docx preset use <name>
|
|
104
|
+
md2docx preset save --name <name> [配置选项]
|
|
93
105
|
md2docx clean
|
|
94
106
|
```
|
|
95
107
|
|
|
@@ -99,6 +111,7 @@ md2docx clean
|
|
|
99
111
|
| ----------------------- | ---------------------------------------- |
|
|
100
112
|
| `<markdown>` | 位置参数;仅在没有其他转换选项时允许使用 |
|
|
101
113
|
| `-f, --file <path>` | Markdown 输入文件 |
|
|
114
|
+
| `--preset <name>` | 本次转换使用指定预设 |
|
|
102
115
|
| `-c, --config <path>` | 自定义配置 JSON |
|
|
103
116
|
| `--style-raw <path>` | 完整底层 Word 样式 JSON |
|
|
104
117
|
| `--style-config <path>` | 受控语义化样式配置 JSON |
|
|
@@ -106,7 +119,7 @@ md2docx clean
|
|
|
106
119
|
| `-h, --help` | 显示帮助 |
|
|
107
120
|
| `-v, --version` | 显示版本号 |
|
|
108
121
|
|
|
109
|
-
位置参数不能和 `--file`、`--config`、`--style-raw`、`--style-config` 或 `--output` 混用。例如:
|
|
122
|
+
位置参数不能和 `--file`、`--preset`、`--config`、`--style-raw`、`--style-config` 或 `--output` 混用。例如:
|
|
110
123
|
|
|
111
124
|
```bash
|
|
112
125
|
md2docx report.md # 正确
|
|
@@ -121,6 +134,7 @@ md2docx -f report.md -o report.docx # 正确
|
|
|
121
134
|
| 参数 | 说明 |
|
|
122
135
|
| --------------------- | ------------------------------------------- |
|
|
123
136
|
| `-f, --file <path>` | 必填,Markdown 输入文件 |
|
|
137
|
+
| `--preset <name>` | 使用预设中的 `config.json` |
|
|
124
138
|
| `-c, --config <path>` | 自定义配置 JSON |
|
|
125
139
|
| `-o, --output <path>` | 输出 Markdown,默认 `<文件名>_formatted.md` |
|
|
126
140
|
|
|
@@ -134,13 +148,27 @@ md2docx export style-config [-o style-config.json]
|
|
|
134
148
|
|
|
135
149
|
`export config` 导出内置 Markdown 处理配置。`export style-raw` 不带 `--file` 时导出内置底层 Word 样式;指定 DOCX 时从该文档提取底层样式。`export style-config` 导出默认语义化样式配置。
|
|
136
150
|
|
|
151
|
+
### preset
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
md2docx preset list
|
|
155
|
+
md2docx preset use academic
|
|
156
|
+
md2docx preset use default
|
|
157
|
+
md2docx preset save --name academic \
|
|
158
|
+
--config config.json \
|
|
159
|
+
--style-raw style-raw.json \
|
|
160
|
+
--style-config style-config.json
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
用户预设位于 `~/.md2docx/presets/<name>/`,其中三个标准 JSON 文件都可省略;缺失项逐一继承系统内置 `default`。文件存在但内容无效时会报错。`preset save` 至少需要一个配置文件,同名保存会完整替换旧预设,未提供的类型改为继承默认值。`--preset` 只影响本次执行,`preset use` 会持久化默认选择。
|
|
164
|
+
|
|
137
165
|
### clean
|
|
138
166
|
|
|
139
167
|
```bash
|
|
140
168
|
md2docx clean
|
|
141
169
|
```
|
|
142
170
|
|
|
143
|
-
`clean`
|
|
171
|
+
`clean` 只删除 `~/.md2docx/` 下可重建的预处理文件、物化资源和样式缓存,保留 `presets/` 与 `settings.json`。命令拒绝跟随符号链接,且可重复执行。
|
|
144
172
|
|
|
145
173
|
npm 卸载不会可靠地清理用户数据。卸载前如需清理,请显式运行:
|
|
146
174
|
|
|
@@ -167,14 +195,21 @@ md2docx export style-config → ./style-config.json
|
|
|
167
195
|
|
|
168
196
|
```text
|
|
169
197
|
~/.md2docx/
|
|
198
|
+
├── settings.json
|
|
199
|
+
├── presets/
|
|
200
|
+
│ └── <预设名称>/
|
|
201
|
+
│ ├── config.json(可选)
|
|
202
|
+
│ ├── style-raw.json(可选)
|
|
203
|
+
│ └── style-config.json(可选)
|
|
170
204
|
├── preprocess/
|
|
171
205
|
│ └── <输入文件名>-<绝对路径哈希>/
|
|
172
206
|
│ ├── <输入文件名>_formatted.md
|
|
173
207
|
│ └── mermaid_*.png
|
|
174
208
|
├── resources/
|
|
175
|
-
│ ├──
|
|
176
|
-
│ ├──
|
|
177
|
-
│ ├── style-
|
|
209
|
+
│ ├── default/
|
|
210
|
+
│ │ ├── config.json
|
|
211
|
+
│ │ ├── style-config.json
|
|
212
|
+
│ │ └── style-raw.json
|
|
178
213
|
│ ├── add-inline-code.lua
|
|
179
214
|
│ └── limit-image-size.lua
|
|
180
215
|
└── style/
|
|
@@ -189,7 +224,7 @@ md2docx export style-config → ./style-config.json
|
|
|
189
224
|
|
|
190
225
|
## 配置
|
|
191
226
|
|
|
192
|
-
内置配置来自 `config/config.json`,并由 `config/config.schema.json` 提供 JSON Schema。推荐先导出再编辑:
|
|
227
|
+
内置配置来自 `config/default/config.json`,并由 `config/config.schema.json` 提供 JSON Schema。推荐先导出再编辑:
|
|
193
228
|
|
|
194
229
|
```bash
|
|
195
230
|
md2docx export config
|
|
@@ -226,7 +261,7 @@ CLI 不支持覆盖单个配置项,所有配置都通过 JSON 文件管理。
|
|
|
226
261
|
|
|
227
262
|
普通用户推荐使用受控的语义化样式配置,只修改程序明确开放的高频选项。其余颜色、尺寸、对齐方式、间距和 Word 样式继承关系继续由内置预设管理。
|
|
228
263
|
|
|
229
|
-
仓库中的 `config/style-config.json` 是可直接复制和修改的默认配置,`config/style-config.schema.json` 用于编辑器提示和校验。完整底层 Word 样式位于 `config/style-raw.json`。
|
|
264
|
+
仓库中的 `config/default/style-config.json` 是可直接复制和修改的默认配置,`config/style-config.schema.json` 用于编辑器提示和校验。完整底层 Word 样式位于 `config/default/style-raw.json`。
|
|
230
265
|
|
|
231
266
|
```json
|
|
232
267
|
{
|
|
@@ -284,9 +319,9 @@ md2docx -f report.md --style-config style-config.json
|
|
|
284
319
|
|
|
285
320
|
| 参数 | 行为 |
|
|
286
321
|
| ------------------- | ----------------------------------- |
|
|
287
|
-
| 都不指定 |
|
|
322
|
+
| 都不指定 | 当前预设 raw + 当前预设 config |
|
|
288
323
|
| 仅 `--style-raw` | 直接使用用户 raw,不应用默认 config |
|
|
289
|
-
| 仅 `--style-config` | 用户 config
|
|
324
|
+
| 仅 `--style-config` | 用户 config 应用到当前预设 raw |
|
|
290
325
|
| 两者都指定 | 用户 config 应用到用户 raw |
|
|
291
326
|
|
|
292
327
|
最终有效的底层样式用于生成 reference DOCX,并通过 Pandoc 的 `--reference-doc` 应用。`--style-raw` 和 `--style-config` 类型固定,不能互换。
|