@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 +46 -26
- package/config/config.json +1 -5
- package/config/config.schema.json +2 -21
- package/config/lua/add-inline-code.lua +6 -0
- package/dist/index.js +1272 -0
- package/package.json +10 -5
- package/src/cli.ts +0 -210
- package/src/config.ts +0 -52
- package/src/index.ts +0 -99
- package/src/paths.ts +0 -34
- package/src/preprocess/caption.ts +0 -107
- package/src/preprocess/index.ts +0 -49
- package/src/preprocess/mermaid.ts +0 -146
- package/src/preprocess/title.ts +0 -144
- package/src/style/extract.ts +0 -653
- package/src/style/generate.ts +0 -65
- package/src/web/app.css +0 -921
- package/src/web/app.js +0 -880
- package/src/web/index.html +0 -114
- package/src/web.ts +0 -512
package/README.md
CHANGED
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
|
|
34
34
|
## 安装
|
|
35
35
|
|
|
36
|
-
**前置依赖**:[
|
|
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
|
-
#
|
|
49
|
-
md2docx docs/example.md
|
|
48
|
+
# 转换 Markdown 为 Word
|
|
49
|
+
md2docx --file docs/example.md
|
|
50
50
|
|
|
51
|
-
#
|
|
52
|
-
md2docx docs/example.md
|
|
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
|
|
54
|
+
# 只执行 Markdown 预处理
|
|
55
|
+
md2docx format --file docs/example.md
|
|
56
56
|
|
|
57
|
-
#
|
|
58
|
-
md2docx
|
|
57
|
+
# 导出可编辑的默认配置和样式
|
|
58
|
+
md2docx export config
|
|
59
|
+
md2docx export style
|
|
59
60
|
|
|
60
|
-
#
|
|
61
|
-
md2docx
|
|
61
|
+
# 从现有 Word 文档提取样式
|
|
62
|
+
md2docx export style --file template.docx
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
所有写文件命令默认拒绝覆盖已有文件。确认覆盖时传入 `--force`。
|
|
66
|
+
不传入任何参数时显示顶层帮助,行为与 `md2docx --help` 相同。
|
|
67
|
+
|
|
68
|
+
## CLI
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
md2docx
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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
|
|
190
|
+
# 查看 CLI 帮助
|
|
191
|
+
bun run src/index.ts --help
|
|
172
192
|
```
|
|
173
193
|
|
|
174
194
|
## 许可
|
package/config/config.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
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
|
}
|