@v1hz/md2docx 1.6.0 → 2.0.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 CHANGED
@@ -33,11 +33,11 @@
33
33
 
34
34
  ## 安装
35
35
 
36
- **前置依赖**:[Bun](https://bun.sh) | [Pandoc](https://pandoc.org)
36
+ **前置依赖**:[Node.js 22.12+](https://nodejs.org) | [Pandoc](https://pandoc.org)
37
37
 
38
38
  ```bash
39
39
  npm install -g @v1hz/md2docx
40
- md2docx docs/example.md
40
+ md2docx --file docs/example.md
41
41
  ```
42
42
 
43
43
  也可通过 `npx @v1hz/md2docx` 直接运行。
@@ -45,34 +45,54 @@ md2docx docs/example.md
45
45
  ## 快速开始
46
46
 
47
47
  ```bash
48
- # 处理 Markdown 并生成 Word 文档
49
- md2docx docs/example.md
48
+ # 转换 Markdown Word
49
+ md2docx --file docs/example.md
50
50
 
51
- # 只预处理,不调用 pandoc
52
- md2docx docs/example.md --pandoc.enabled false
51
+ # 使用自定义配置、样式和输出路径
52
+ md2docx -f docs/example.md -c config.json -s style.json -o output/example.docx
53
53
 
54
- # 指定输出路径
55
- md2docx docs/example.md -o output/example.docx
54
+ # 只执行 Markdown 预处理
55
+ md2docx format --file docs/example.md
56
56
 
57
- # 打开 web 网页自定义配置
58
- md2docx --web
57
+ # 导出可编辑的默认配置和样式
58
+ md2docx export config
59
+ md2docx export style
59
60
 
60
- # 使用自定义配置文件
61
- md2docx docs/example.md --config ./my-config.json
61
+ # 从现有 Word 文档提取样式
62
+ md2docx export style --file template.docx
63
+ ```
64
+
65
+ 所有写文件命令默认拒绝覆盖已有文件。确认覆盖时传入 `--force`。
66
+ 不传入任何参数时显示顶层帮助,行为与 `md2docx --help` 相同。
67
+
68
+ ## CLI
62
69
 
63
- # 清除缓存(预处理中间产物、样式模板等)
64
- md2docx clean
70
+ ```text
71
+ md2docx -f <markdown> [选项]
72
+ md2docx format -f <markdown> [选项]
73
+ md2docx export config [选项]
74
+ md2docx export style [选项]
65
75
  ```
66
76
 
67
- ## 配置
77
+ `--file` 在顶层转换和 `format` 命令中必填;在 `export style` 中可选,不提供时导出内置默认样式,提供 DOCX 时从该文档提取样式。
68
78
 
69
- 配置文件位于 `config/config.json`,通过 JSON Schema 提供 IDE 校验。
79
+ | 参数 | 说明 |
80
+ | --------------------- | ------------------------------ |
81
+ | `-f, --file <path>` | 输入文件 |
82
+ | `-c, --config <path>` | 自定义配置文件 |
83
+ | `-s, --style <path>` | 自定义样式文件(仅 Word 转换) |
84
+ | `-o, --output <path>` | 完整输出文件路径 |
85
+ | `--force` | 覆盖已有输出 |
86
+ | `-h, --help` | 显示当前命令帮助 |
87
+ | `-v, --version` | 显示版本号 |
70
88
 
71
- 所有配置项均可通过命令行覆盖:
89
+ 默认输出分别为 `<源文件名>.docx`、`<源文件名>_formatted.md`、`config.json` 和
90
+ `style.json`。从 DOCX 提取样式时,默认输出 `<DOCX 文件名>_style.json`。
72
91
 
73
- ```bash
74
- md2docx docs/example.md --figureCaption.enabled false
75
- ```
92
+ ## 配置
93
+
94
+ 配置文件位于 `config/config.json`,通过 JSON Schema 提供 IDE 校验。使用
95
+ `md2docx export config` 导出副本,修改后通过 `--config` 指定;CLI 不提供单个配置项覆盖。
76
96
 
77
97
  | 配置项 | 说明 | 默认值 |
78
98
  | -------------------------------- | ------------------------------------------------------------ | --------------------- |
@@ -91,8 +111,6 @@ md2docx docs/example.md --figureCaption.enabled false
91
111
  | `renderMermaid.enabled` | 渲染 Mermaid 图表为 PNG | `true` |
92
112
  | `renderMermaid.theme` | 图表主题 | `"tokyo-night-light"` |
93
113
  | `renderMermaid.density` | 图片清晰度(DPI,最小 72) | `200` |
94
- | `pandoc.enabled` | 生成 Word 文档 | `true` |
95
- | `pandoc.outputName` | 输出文件名,`{file_name}` 代表源文件名 | `"{file_name}.docx"` |
96
114
 
97
115
  ## 样式定制
98
116
 
@@ -103,7 +121,7 @@ md2docx docs/example.md --figureCaption.enabled false
103
121
  如果你有一个排版精美的 docx 模板,可以提取其样式:
104
122
 
105
123
  ```bash
106
- bun run src/style/extract.ts
124
+ md2docx export style --file template.docx
107
125
  ```
108
126
 
109
127
  提取后修改 `config/style.json`,转换时会自动使用这些样式生成输出文档。
@@ -151,11 +169,13 @@ pandoc → DOCX ← 以 --reference-doc 传入样式模板
151
169
 
152
170
  ### 从源码运行
153
171
 
172
+ 从源码开发需要安装 Bun;发布后的 CLI 使用 Node.js 运行,不依赖 Bun。
173
+
154
174
  ```bash
155
175
  git clone https://github.com/WXY-V1hZ/md2docx.git
156
176
  cd md2docx
157
177
  bun install
158
- bun run src/index.ts docs/example.md
178
+ bun run src/index.ts --file docs/example.md
159
179
  ```
160
180
 
161
181
  ### 命令
@@ -167,8 +187,8 @@ bun test
167
187
  # 类型检查 + 代码检查 + 格式检查
168
188
  bun check
169
189
 
170
- # 清除缓存
171
- bun run src/index.ts clean
190
+ # 查看 CLI 帮助
191
+ bun run src/index.ts --help
172
192
  ```
173
193
 
174
194
  ## 许可
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "./config.schema.json",
2
+ "$schema": "https://raw.githubusercontent.com/WXY-V1hZ/md2docx/main/config/config.schema.json",
3
3
  "figureCaption": {
4
4
  "enabled": true,
5
5
  "format": "图 {n}",
@@ -26,9 +26,5 @@
26
26
  "detectTitle": {
27
27
  "enabled": true,
28
28
  "strategy": "first-h1"
29
- },
30
- "pandoc": {
31
- "enabled": true,
32
- "outputName": "{file_name}.docx"
33
29
  }
34
30
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://raw.githubusercontent.com/WXY-V1hZ/md2docx/main/config.schema.json",
3
+ "$id": "https://raw.githubusercontent.com/WXY-V1hZ/md2docx/main/config/config.schema.json",
4
4
  "title": "md2docx 配置",
5
5
  "description": "md2docx 默认设置",
6
6
  "type": "object",
@@ -117,24 +117,6 @@
117
117
  },
118
118
  "required": ["enabled", "theme", "density"]
119
119
  },
120
- "pandoc": {
121
- "description": "Word 导出",
122
- "type": "object",
123
- "additionalProperties": false,
124
- "properties": {
125
- "enabled": {
126
- "description": "生成 Word 文档",
127
- "type": "boolean",
128
- "default": true
129
- },
130
- "outputName": {
131
- "description": "输出文件名,{file_name} 代表源文件名",
132
- "type": "string",
133
- "default": "{file_name}.docx"
134
- }
135
- },
136
- "required": ["enabled", "outputName"]
137
- },
138
120
  "detectTitle": {
139
121
  "description": "文档标题",
140
122
  "type": "object",
@@ -167,7 +149,6 @@
167
149
  "normalizeHeadings",
168
150
  "numberHeadings",
169
151
  "renderMermaid",
170
- "detectTitle",
171
- "pandoc"
152
+ "detectTitle"
172
153
  ]
173
154
  }
@@ -0,0 +1,6 @@
1
+ -- Author: Achuan-2
2
+ function Code(el)
3
+ -- 为行内代码添加一个自定义的 Word 样式名称
4
+ return pandoc.Span(el.text, {["custom-style"] = "Inline Code"})
5
+ end
6
+ return { Code = Code }