markdown-paper 2.2.4 → 2.3.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 +19 -32
- package/bun.lockb +0 -0
- package/lib/main.ts +8 -2
- package/package.json +2 -1
- package/theme/aps/aps.ts +0 -162
- package/theme/theme.ts +1 -1
package/README.md
CHANGED
|
@@ -23,10 +23,24 @@
|
|
|
23
23
|
|
|
24
24
|
正文
|
|
25
25
|
|
|
26
|
+
#### 1.1.2 数学公式
|
|
27
|
+
|
|
28
|
+
段内数学公式: $c = \pm\sqrt{a^2 + b^2}$
|
|
29
|
+
|
|
30
|
+
单独数学公式:
|
|
31
|
+
|
|
32
|
+
$$
|
|
33
|
+
c = \pm\sqrt{a^2 + b^2}
|
|
34
|
+
$$
|
|
35
|
+
|
|
36
|
+
#### 1.1.3 图片
|
|
37
|
+
|
|
26
38
|

|
|
27
39
|
|
|
28
40
|
> 图片标题
|
|
29
41
|
|
|
42
|
+
#### 1.1.4 表格
|
|
43
|
+
|
|
30
44
|
> 表格标题
|
|
31
45
|
|
|
32
46
|
| 表头1 | 表头2 |
|
|
@@ -42,7 +56,7 @@
|
|
|
42
56
|
##### 附录
|
|
43
57
|
```
|
|
44
58
|
|
|
45
|
-
>
|
|
59
|
+
> 数学公式语法详见 [https://katex.org](https://katex.org)
|
|
46
60
|
|
|
47
61
|
## 2 安装 `Bun`
|
|
48
62
|
|
|
@@ -60,7 +74,7 @@ bun add -g markdown-paper
|
|
|
60
74
|
|
|
61
75
|
运行 `mdp` 命令以使用 `MarkdownPaper` 命令行工具从 `Markdown` 文件生成论文
|
|
62
76
|
|
|
63
|
-
如果您不熟悉命令行工具, 可以尝试我的另一个项目 [EasyPaper](https://github.com/LeafYeeXYZ/EasyPaper),
|
|
77
|
+
如果您不熟悉命令行工具, 可以尝试我的另一个项目 [EasyPaper](https://github.com/LeafYeeXYZ/EasyPaper), 它实现了大部分 `MarkdownPaper` 的功能并提供了图形界面
|
|
64
78
|
|
|
65
79
|
```bash
|
|
66
80
|
# 查看帮助信息
|
|
@@ -100,38 +114,11 @@ mdp example.md --outputDOCX
|
|
|
100
114
|
| `--enPunctuation` | 将正文中的中文标点符号替换为英文标点符号, 默认不替换<br>仅替换 `PDF` 和 `DOCX` 文件 |
|
|
101
115
|
|
|
102
116
|
### 编写格式
|
|
103
|
-
|
|
104
|
-
# 中文标题
|
|
105
|
-
#author# 作者信息
|
|
106
|
-
#school# 单位信息
|
|
107
|
-
#abstract# 摘要内容
|
|
108
|
-
#keywords# 关键词内容
|
|
109
|
-
|
|
110
|
-
## 1 一级标题
|
|
111
|
-
### 1.1 二级标题
|
|
112
|
-
#### 1.1.1 三级标题
|
|
113
|
-
正文
|
|
114
|
-
|
|
115
|
-

|
|
116
|
-
|
|
117
|
-
> 图片标题
|
|
118
|
-
|
|
119
|
-
> 表格标题
|
|
120
|
-
|
|
121
|
-
| 表头1 | 表头2 |
|
|
122
|
-
| :---: | :---: |
|
|
123
|
-
| 内容1 | 内容2 |
|
|
124
|
-
|
|
125
|
-
##### 参考文献
|
|
126
|
-
- 文献1
|
|
127
|
-
- 文献2
|
|
128
|
-
- 文献3
|
|
129
|
-
|
|
130
|
-
##### 附录
|
|
131
|
-
```
|
|
117
|
+
同上
|
|
132
118
|
|
|
133
119
|
# 更新日志
|
|
134
|
-
- `2.
|
|
120
|
+
- `2.3.0` (2024-08-31): 支持数学公式
|
|
121
|
+
- `2.2.0` (2024-08-26): 半重构, 优化导入导出, 优化文档
|
|
135
122
|
- `2.1.1` (2024-07-12): 修复字体错误
|
|
136
123
|
- `2.1.0` (2024-06-26): 支持 `MacOS` 系统, 改为在线加载字体
|
|
137
124
|
- `2.0.0` (2024-06-20): 重构代码, 完善模板功能
|
package/bun.lockb
CHANGED
|
Binary file
|
package/lib/main.ts
CHANGED
|
@@ -3,9 +3,12 @@ import puppeteer from 'puppeteer'
|
|
|
3
3
|
import fs from 'node:fs/promises'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { readFileSync } from 'node:fs'
|
|
6
|
-
import { APS
|
|
6
|
+
import { APS } from '../theme/aps/aps'
|
|
7
7
|
import type { MarkdownPaperTheme } from '../theme/theme'
|
|
8
8
|
import type { PDFOptions } from 'puppeteer'
|
|
9
|
+
import markedKatex from 'marked-katex-extension'
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import katexCss from 'katex/dist/katex.css' with { type: 'text' }
|
|
9
12
|
|
|
10
13
|
/** 应用参数 */
|
|
11
14
|
class MarkdownPaperOptions {
|
|
@@ -178,6 +181,8 @@ async function mdToHtml(
|
|
|
178
181
|
theme: MarkdownPaperTheme,
|
|
179
182
|
pageTitle: string = 'MarkdownPaper'
|
|
180
183
|
): Promise<string> {
|
|
184
|
+
// 设置 marked
|
|
185
|
+
marked.use(markedKatex({ throwOnError: false }))
|
|
181
186
|
// 预处理 markdown
|
|
182
187
|
let html = await theme.preParseMarkdown(md)
|
|
183
188
|
// 转换 markdown 为 html
|
|
@@ -188,6 +193,7 @@ async function mdToHtml(
|
|
|
188
193
|
<meta charset="UTF-8">
|
|
189
194
|
<title>${pageTitle}</title>
|
|
190
195
|
<style>${theme.css}</style>
|
|
196
|
+
<style>\n${katexCss}\n</style>
|
|
191
197
|
</head>
|
|
192
198
|
<body>
|
|
193
199
|
${await marked(html)}
|
|
@@ -206,7 +212,7 @@ export {
|
|
|
206
212
|
htmlToPdf,
|
|
207
213
|
pdfToDocx,
|
|
208
214
|
mdToHtml,
|
|
209
|
-
|
|
215
|
+
APS
|
|
210
216
|
}
|
|
211
217
|
export type {
|
|
212
218
|
MarkdownPaperTheme
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-paper",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "LeafYeeXYZ",
|
|
7
7
|
"email": "xiaoyezi@leafyee.xyz"
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"marked": "^12.0.2",
|
|
27
|
+
"marked-katex-extension": "^5.1.1",
|
|
27
28
|
"puppeteer": "^22.9.0"
|
|
28
29
|
}
|
|
29
30
|
}
|
package/theme/aps/aps.ts
CHANGED
|
@@ -119,166 +119,4 @@ export class APS implements MarkdownPaperTheme {
|
|
|
119
119
|
footerTemplate: hideFooter ? `<div></div>` : `<div style="font-size: 9px; font-family: 'SimSun'; color: #333; padding: 5px; margin: 0 auto;">第 <span class="pageNumber"></span> 页 / 共 <span class="totalPages"></span> 页</div>`,
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export const baseAPS: MarkdownPaperTheme = {
|
|
125
|
-
css: `
|
|
126
|
-
* {
|
|
127
|
-
font-family: 'Times', 'Times New Roman', '宋体', 'SimSun', '华文宋体', 'STSong'; /* 所有数字和英文字体都用 Times New Roman */
|
|
128
|
-
line-height: 1.55em; /* 1.5倍行距 */
|
|
129
|
-
margin: 0;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
h1 { /* 中文题目: 二号黑体 */
|
|
133
|
-
font-size: 29px;
|
|
134
|
-
font-weight: normal;
|
|
135
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
136
|
-
text-align: center;
|
|
137
|
-
margin-bottom: 9px;
|
|
138
|
-
}
|
|
139
|
-
.author { /* 作者姓名: 四号仿宋 */
|
|
140
|
-
font-size: 18px;
|
|
141
|
-
font-weight: normal;
|
|
142
|
-
font-family: '仿宋', 'Fangsong', '华文仿宋', 'STFangsong';
|
|
143
|
-
text-align: center;
|
|
144
|
-
margin-bottom: 3px;
|
|
145
|
-
}
|
|
146
|
-
.school { /* 作者单位: 小五宋体 */
|
|
147
|
-
font-size: 12px;
|
|
148
|
-
text-align: center;
|
|
149
|
-
margin-bottom: 38px;
|
|
150
|
-
}
|
|
151
|
-
.abstract { /* 摘要和关键词: 五号宋体 */
|
|
152
|
-
font-size: 14px;
|
|
153
|
-
text-align: justify;
|
|
154
|
-
padding: 0 28px;
|
|
155
|
-
&::before {
|
|
156
|
-
content: '摘 要';
|
|
157
|
-
font-weight: normal;
|
|
158
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
159
|
-
display: inline-block;
|
|
160
|
-
margin-right: 14px;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
.keywords {
|
|
164
|
-
font-size: 14px;
|
|
165
|
-
margin-bottom: 31px;
|
|
166
|
-
padding: 0 28px;
|
|
167
|
-
&::before {
|
|
168
|
-
content: '关键词';
|
|
169
|
-
font-weight: normal;
|
|
170
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
171
|
-
display: inline-block;
|
|
172
|
-
margin-right: 14px;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
h2 { /* 一级标题: 四号宋体 */
|
|
177
|
-
font-size: 18px;
|
|
178
|
-
font-weight: normal;
|
|
179
|
-
margin: 7px 0;
|
|
180
|
-
}
|
|
181
|
-
h3 { /* 二级标题: 五号黑体 */
|
|
182
|
-
font-size: 14px;
|
|
183
|
-
font-weight: normal;
|
|
184
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
185
|
-
margin: 5px 0;
|
|
186
|
-
}
|
|
187
|
-
h4 { /* 三级标题: 五号黑体 */
|
|
188
|
-
font-size: 14px;
|
|
189
|
-
font-weight: normal;
|
|
190
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
191
|
-
margin: 3px 0;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
p { /* 正文: 五号宋体 */
|
|
195
|
-
font-size: 14px;
|
|
196
|
-
text-indent: 24px;
|
|
197
|
-
text-align: justify;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
h5 { /* "参考文献": 五号黑体 */
|
|
201
|
-
font-size: 14px;
|
|
202
|
-
font-weight: normal;
|
|
203
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
204
|
-
text-align: center;
|
|
205
|
-
margin-bottom: 7px;
|
|
206
|
-
margin-top: 20px;
|
|
207
|
-
}
|
|
208
|
-
ul, ol { /* 参考文献的项目: 小五号宋体 */
|
|
209
|
-
list-style-type: none;
|
|
210
|
-
padding: 0;
|
|
211
|
-
& > li {
|
|
212
|
-
font-size: 12px;
|
|
213
|
-
margin: 6px 0;
|
|
214
|
-
text-align: justify;
|
|
215
|
-
text-indent: -24px;
|
|
216
|
-
padding-left: 24px;
|
|
217
|
-
}
|
|
218
|
-
& a {
|
|
219
|
-
text-decoration: none;
|
|
220
|
-
color: black;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
img {
|
|
225
|
-
display: block;
|
|
226
|
-
max-width: 100%;
|
|
227
|
-
margin: 0 auto;
|
|
228
|
-
margin-top: 10px;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
blockquote, blockquote > p { /* 图片和表格的标题: 小五号宋体 */
|
|
232
|
-
font-size: 12px;
|
|
233
|
-
font-weight: normal;
|
|
234
|
-
text-align: center;
|
|
235
|
-
margin: 0;
|
|
236
|
-
}
|
|
237
|
-
blockquote > p { margin: 6px 0; }
|
|
238
|
-
table { /* 表格: 小五号宋体 */
|
|
239
|
-
font-size: 12px;
|
|
240
|
-
position: relative;
|
|
241
|
-
border-top: 1px solid black;
|
|
242
|
-
border-bottom: 1px solid black;
|
|
243
|
-
width: 100%;
|
|
244
|
-
max-width: 100%;
|
|
245
|
-
margin: 0 auto;
|
|
246
|
-
margin-bottom: 10px;
|
|
247
|
-
& th, & td {
|
|
248
|
-
font-weight: normal;
|
|
249
|
-
}
|
|
250
|
-
& thead::after { /* 用来做三线表中间的横线 */
|
|
251
|
-
content: '';
|
|
252
|
-
display: block;
|
|
253
|
-
position: absolute;
|
|
254
|
-
border-top: 1px solid #00000060;
|
|
255
|
-
width: 100%;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
b, strong { /* 加粗按黑体处理 */
|
|
260
|
-
font-weight: normal;
|
|
261
|
-
font-family: '黑体', 'SimHei', '华文黑体', 'STHeiti';
|
|
262
|
-
}
|
|
263
|
-
`,
|
|
264
|
-
preParseMarkdown: async (md: string): Promise<string> => {
|
|
265
|
-
// 作者
|
|
266
|
-
md = md.replace(/#author# (.*)/mg, '<div class="author">$1</div>')
|
|
267
|
-
// 单位
|
|
268
|
-
md = md.replace(/#school# (.*)/mg, '<div class="school">$1</div>')
|
|
269
|
-
// 关键词
|
|
270
|
-
md = md.replace(/#keywords# (.*)/mg, '<div class="keywords">$1</div>')
|
|
271
|
-
// 摘要
|
|
272
|
-
md = md.replace(/#abstract# (.*)/mg, '<div class="abstract">$1</div>')
|
|
273
|
-
// 返回处理后的字符串
|
|
274
|
-
return md
|
|
275
|
-
},
|
|
276
|
-
preParseHTML: async (html: string): Promise<string> => {
|
|
277
|
-
// 把包裹图片的 p 标签去掉
|
|
278
|
-
html = html.replace(/<p><img (.*?)><\/p>/g, '<img $1>')
|
|
279
|
-
// 返回处理后的字符串
|
|
280
|
-
return html
|
|
281
|
-
},
|
|
282
|
-
script: () => {},
|
|
283
|
-
pdfOptions: {}
|
|
284
122
|
}
|
package/theme/theme.ts
CHANGED