markdown-paper 2.0.0 → 2.1.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 +82 -82
- package/bin/mdp.ts +36 -36
- package/bun.lockb +0 -0
- package/lib/docx.ts +18 -18
- package/lib/main.ts +167 -176
- package/license +673 -673
- package/package.json +3 -3
- package/theme/aps/aps.css +136 -133
- package/theme/aps/aps.md +40 -40
- package/theme/aps/aps.ts +129 -121
- package/theme/theme.ts +44 -44
- package/tsconfig.json +27 -27
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.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "LeafYeeXYZ",
|
|
7
7
|
"email": "xiaoyezi@leafyee.xyz"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"mdp": "bun ./bin/mdp.ts",
|
|
12
12
|
"pub": "npm publish",
|
|
13
|
-
"try": "bun mdp
|
|
13
|
+
"try": "bun mdp ./论文.md --out=./demo/论文 --outputHTML"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
16
|
"mdp": "./bin/mdp.ts"
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"marked": "^12.0.2",
|
|
26
|
-
"puppeteer
|
|
26
|
+
"puppeteer": "^22.9.0"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/theme/aps/aps.css
CHANGED
|
@@ -1,134 +1,137 @@
|
|
|
1
|
-
* {
|
|
2
|
-
font-family: '
|
|
3
|
-
line-height: 1.55em; /* 1.5倍行距 */
|
|
4
|
-
margin: 0;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
h1 { /* 中文题目: 二号黑体 */
|
|
8
|
-
font-size: 29px;
|
|
9
|
-
font-weight:
|
|
10
|
-
font-family: '
|
|
11
|
-
text-align: center;
|
|
12
|
-
margin-bottom: 9px;
|
|
13
|
-
}
|
|
14
|
-
.author { /* 作者姓名: 四号仿宋 */
|
|
15
|
-
font-size: 18px;
|
|
16
|
-
font-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
&
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
* {
|
|
2
|
+
font-family: 'Noto Serif', 'Noto Serif SC'; /* 所有数字和英文字体都用 Times New Roman */
|
|
3
|
+
line-height: 1.55em; /* 1.5倍行距 */
|
|
4
|
+
margin: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
h1 { /* 中文题目: 二号黑体 */
|
|
8
|
+
font-size: 29px;
|
|
9
|
+
font-weight: 500;
|
|
10
|
+
font-family: 'Noto Sans SC';
|
|
11
|
+
text-align: center;
|
|
12
|
+
margin-bottom: 9px;
|
|
13
|
+
}
|
|
14
|
+
.author { /* 作者姓名: 四号仿宋 */
|
|
15
|
+
font-size: 18px;
|
|
16
|
+
font-weight: 300;
|
|
17
|
+
font-family: 'Noto Serif SC';
|
|
18
|
+
text-align: center;
|
|
19
|
+
margin-bottom: 3px;
|
|
20
|
+
}
|
|
21
|
+
.school { /* 作者单位: 小五宋体 */
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
text-align: center;
|
|
24
|
+
margin-bottom: 38px;
|
|
25
|
+
}
|
|
26
|
+
.abstract { /* 摘要和关键词: 五号宋体 */
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
text-align: justify;
|
|
29
|
+
padding: 0 28px;
|
|
30
|
+
&::before {
|
|
31
|
+
content: '摘 要';
|
|
32
|
+
font-weight: 500;
|
|
33
|
+
font-family: 'Noto Sans SC';
|
|
34
|
+
display: inline-block;
|
|
35
|
+
margin-right: 14px;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
.keywords {
|
|
39
|
+
font-size: 14px;
|
|
40
|
+
margin-bottom: 31px;
|
|
41
|
+
padding: 0 28px;
|
|
42
|
+
&::before {
|
|
43
|
+
content: '关键词';
|
|
44
|
+
font-weight: 500;
|
|
45
|
+
font-family: 'Noto Sans SC';
|
|
46
|
+
display: inline-block;
|
|
47
|
+
margin-right: 14px;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
h2 { /* 一级标题: 四号宋体 */
|
|
52
|
+
font-size: 18px;
|
|
53
|
+
font-weight: normal;
|
|
54
|
+
margin: 7px 0;
|
|
55
|
+
}
|
|
56
|
+
h3 { /* 二级标题: 五号黑体 */
|
|
57
|
+
font-size: 14px;
|
|
58
|
+
font-weight: 500;
|
|
59
|
+
font-family: 'Noto Sans SC';
|
|
60
|
+
margin: 5px 0;
|
|
61
|
+
}
|
|
62
|
+
h4 { /* 三级标题: 五号黑体 */
|
|
63
|
+
font-size: 14px;
|
|
64
|
+
font-weight: 500;
|
|
65
|
+
font-family: 'Noto Sans SC';
|
|
66
|
+
margin: 3px 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
p { /* 正文: 五号宋体 */
|
|
70
|
+
font-size: 14px;
|
|
71
|
+
text-indent: 24px;
|
|
72
|
+
text-align: justify;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
h5 { /* "参考文献": 五号黑体 */
|
|
76
|
+
font-size: 14px;
|
|
77
|
+
font-weight: 500;
|
|
78
|
+
font-family: 'Noto Sans SC';
|
|
79
|
+
text-align: center;
|
|
80
|
+
margin-bottom: 7px;
|
|
81
|
+
margin-top: 20px;
|
|
82
|
+
}
|
|
83
|
+
ul, ol { /* 参考文献的项目: 小五号宋体 */
|
|
84
|
+
list-style-type: none;
|
|
85
|
+
padding: 0;
|
|
86
|
+
& > li {
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
margin: 6px 0;
|
|
89
|
+
text-align: justify;
|
|
90
|
+
text-indent: -24px;
|
|
91
|
+
padding-left: 24px;
|
|
92
|
+
}
|
|
93
|
+
& a {
|
|
94
|
+
text-decoration: none;
|
|
95
|
+
color: black;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
img {
|
|
100
|
+
display: block;
|
|
101
|
+
max-width: 100%;
|
|
102
|
+
margin: 0 auto;
|
|
103
|
+
margin-top: 10px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
blockquote, blockquote > p { /* 图片和表格的标题: 小五号宋体 */
|
|
107
|
+
font-size: 12px;
|
|
108
|
+
font-weight: normal;
|
|
109
|
+
text-align: center;
|
|
110
|
+
margin: 0;
|
|
111
|
+
}
|
|
112
|
+
blockquote > p { margin: 6px 0; }
|
|
113
|
+
table { /* 表格: 小五号宋体 */
|
|
114
|
+
font-size: 12px;
|
|
115
|
+
position: relative;
|
|
116
|
+
border-top: 1px solid black;
|
|
117
|
+
border-bottom: 1px solid black;
|
|
118
|
+
width: 100%;
|
|
119
|
+
max-width: 100%;
|
|
120
|
+
margin: 0 auto;
|
|
121
|
+
margin-bottom: 10px;
|
|
122
|
+
& th, & td {
|
|
123
|
+
font-weight: normal;
|
|
124
|
+
}
|
|
125
|
+
& thead::after { /* 用来做三线表中间的横线 */
|
|
126
|
+
content: '';
|
|
127
|
+
display: block;
|
|
128
|
+
position: absolute;
|
|
129
|
+
border-top: 1px solid #00000060;
|
|
130
|
+
width: 100%;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
b, strong { /* 加粗按黑体处理 */
|
|
135
|
+
font-weight: 500;
|
|
136
|
+
font-family: 'Noto Sans SC';
|
|
134
137
|
}
|
package/theme/aps/aps.md
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
# APS 模板
|
|
2
|
-
`Acta Psychologica Sinica`, 心理学报
|
|
3
|
-
|
|
4
|
-
## 额外命令行参数
|
|
5
|
-
| 参数 | 说明 |
|
|
6
|
-
| :---: | :---: |
|
|
7
|
-
| `--showTitle` | 在页眉显示文件名, 默认不显示 |
|
|
8
|
-
| `--hideFooter` | 隐藏页码, 默认显示 |
|
|
9
|
-
| `--zhPunctuation` | 将正文中的英文标点符号替换为中文标点符号, 默认不替换<br>仅替换 `PDF` 和 `DOCX` 文件 |
|
|
10
|
-
| `--enPunctuation` | 将正文中的中文标点符号替换为英文标点符号, 默认不替换<br>仅替换 `PDF` 和 `DOCX` 文件 |
|
|
11
|
-
|
|
12
|
-
## 编写格式
|
|
13
|
-
```markdown
|
|
14
|
-
# 中文标题
|
|
15
|
-
#author# 作者信息
|
|
16
|
-
#school# 单位信息
|
|
17
|
-
#abstract# 摘要内容
|
|
18
|
-
#keywords# 关键词内容
|
|
19
|
-
|
|
20
|
-
## 1 一级标题
|
|
21
|
-
### 1.1 二级标题
|
|
22
|
-
#### 1.1.1 三级标题
|
|
23
|
-
正文
|
|
24
|
-
|
|
25
|
-

|
|
26
|
-
|
|
27
|
-
> 图片标题
|
|
28
|
-
|
|
29
|
-
> 表格标题
|
|
30
|
-
|
|
31
|
-
| 表头1 | 表头2 |
|
|
32
|
-
| :---: | :---: |
|
|
33
|
-
| 内容1 | 内容2 |
|
|
34
|
-
|
|
35
|
-
##### 参考文献
|
|
36
|
-
- 文献1
|
|
37
|
-
- 文献2
|
|
38
|
-
- 文献3
|
|
39
|
-
|
|
40
|
-
##### 附录
|
|
1
|
+
# APS 模板
|
|
2
|
+
`Acta Psychologica Sinica`, 心理学报
|
|
3
|
+
|
|
4
|
+
## 额外命令行参数
|
|
5
|
+
| 参数 | 说明 |
|
|
6
|
+
| :---: | :---: |
|
|
7
|
+
| `--showTitle` | 在页眉显示文件名, 默认不显示 |
|
|
8
|
+
| `--hideFooter` | 隐藏页码, 默认显示 |
|
|
9
|
+
| `--zhPunctuation` | 将正文中的英文标点符号替换为中文标点符号, 默认不替换<br>仅替换 `PDF` 和 `DOCX` 文件 |
|
|
10
|
+
| `--enPunctuation` | 将正文中的中文标点符号替换为英文标点符号, 默认不替换<br>仅替换 `PDF` 和 `DOCX` 文件 |
|
|
11
|
+
|
|
12
|
+
## 编写格式
|
|
13
|
+
```markdown
|
|
14
|
+
# 中文标题
|
|
15
|
+
#author# 作者信息
|
|
16
|
+
#school# 单位信息
|
|
17
|
+
#abstract# 摘要内容
|
|
18
|
+
#keywords# 关键词内容
|
|
19
|
+
|
|
20
|
+
## 1 一级标题
|
|
21
|
+
### 1.1 二级标题
|
|
22
|
+
#### 1.1.1 三级标题
|
|
23
|
+
正文
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
> 图片标题
|
|
28
|
+
|
|
29
|
+
> 表格标题
|
|
30
|
+
|
|
31
|
+
| 表头1 | 表头2 |
|
|
32
|
+
| :---: | :---: |
|
|
33
|
+
| 内容1 | 内容2 |
|
|
34
|
+
|
|
35
|
+
##### 参考文献
|
|
36
|
+
- 文献1
|
|
37
|
+
- 文献2
|
|
38
|
+
- 文献3
|
|
39
|
+
|
|
40
|
+
##### 附录
|
|
41
41
|
```
|
package/theme/aps/aps.ts
CHANGED
|
@@ -1,122 +1,130 @@
|
|
|
1
|
-
import { Theme } from '../theme'
|
|
2
|
-
import { readFileSync } from 'node:fs'
|
|
3
|
-
import { resolve } from 'node:path'
|
|
4
|
-
import type { PDFOptions } from 'puppeteer-core'
|
|
5
|
-
|
|
6
|
-
export class APS extends Theme {
|
|
7
|
-
|
|
8
|
-
css: string
|
|
9
|
-
preParseMarkdown: (md: string) => string
|
|
10
|
-
preParseHTML: (html: string) => string
|
|
11
|
-
script: () => void
|
|
12
|
-
pdfOptions: PDFOptions
|
|
13
|
-
|
|
14
|
-
constructor(args: string[], cwd: string) {
|
|
15
|
-
|
|
16
|
-
super(args, cwd)
|
|
17
|
-
|
|
18
|
-
// 默认自定义参数
|
|
19
|
-
let showTitle: boolean = false
|
|
20
|
-
let hideFooter: boolean = false
|
|
21
|
-
let zhPunctuation: boolean = false
|
|
22
|
-
let enPunctuation: boolean = false
|
|
23
|
-
// 解析参数
|
|
24
|
-
args.forEach(arg => {
|
|
25
|
-
switch (arg.split('=')[0]) {
|
|
26
|
-
case '--showTitle': showTitle = true; break
|
|
27
|
-
case '--hideFooter': hideFooter = true; break
|
|
28
|
-
case '--zhPunctuation': zhPunctuation = true; break
|
|
29
|
-
case '--enPunctuation': enPunctuation = true; break
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
// css
|
|
34
|
-
this.css = readFileSync(resolve(import.meta.dir, 'aps.css'), 'utf-8')
|
|
35
|
-
|
|
36
|
-
// preParseMarkdown
|
|
37
|
-
this.preParseMarkdown = (md: string): string => {
|
|
38
|
-
// 作者
|
|
39
|
-
md = md.replace(/#author# (.*)/mg, '<div class="author">$1</div>')
|
|
40
|
-
// 单位
|
|
41
|
-
md = md.replace(/#school# (.*)/mg, '<div class="school">$1</div>')
|
|
42
|
-
// 关键词
|
|
43
|
-
md = md.replace(/#keywords# (.*)/mg, '<div class="keywords">$1</div>')
|
|
44
|
-
// 摘要
|
|
45
|
-
md = md.replace(/#abstract# (.*)/mg, '<div class="abstract">$1</div>')
|
|
46
|
-
// 返回处理后的字符串
|
|
47
|
-
return md
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// preParseHTML
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
html = html.replace(/<p><img (.*?)><\/p>/g, '<img $1>')
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
text =
|
|
72
|
-
//
|
|
73
|
-
text = text.replace(
|
|
74
|
-
//
|
|
75
|
-
text = text.replace(
|
|
76
|
-
//
|
|
77
|
-
text = text.replace(
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
text =
|
|
95
|
-
//
|
|
96
|
-
text = text.replace(
|
|
97
|
-
//
|
|
98
|
-
text = text.replace(
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
import { Theme } from '../theme'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import type { PDFOptions } from 'puppeteer-core'
|
|
5
|
+
|
|
6
|
+
export class APS extends Theme {
|
|
7
|
+
|
|
8
|
+
css: string
|
|
9
|
+
preParseMarkdown: (md: string) => string
|
|
10
|
+
preParseHTML: (html: string) => string
|
|
11
|
+
script: () => void
|
|
12
|
+
pdfOptions: PDFOptions
|
|
13
|
+
|
|
14
|
+
constructor(args: string[], cwd: string) {
|
|
15
|
+
|
|
16
|
+
super(args, cwd)
|
|
17
|
+
|
|
18
|
+
// 默认自定义参数
|
|
19
|
+
let showTitle: boolean = false
|
|
20
|
+
let hideFooter: boolean = false
|
|
21
|
+
let zhPunctuation: boolean = false
|
|
22
|
+
let enPunctuation: boolean = false
|
|
23
|
+
// 解析参数
|
|
24
|
+
args.forEach(arg => {
|
|
25
|
+
switch (arg.split('=')[0]) {
|
|
26
|
+
case '--showTitle': showTitle = true; break
|
|
27
|
+
case '--hideFooter': hideFooter = true; break
|
|
28
|
+
case '--zhPunctuation': zhPunctuation = true; break
|
|
29
|
+
case '--enPunctuation': enPunctuation = true; break
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// css
|
|
34
|
+
this.css = readFileSync(resolve(import.meta.dir, 'aps.css'), 'utf-8')
|
|
35
|
+
|
|
36
|
+
// preParseMarkdown
|
|
37
|
+
this.preParseMarkdown = (md: string): string => {
|
|
38
|
+
// 作者
|
|
39
|
+
md = md.replace(/#author# (.*)/mg, '<div class="author">$1</div>')
|
|
40
|
+
// 单位
|
|
41
|
+
md = md.replace(/#school# (.*)/mg, '<div class="school">$1</div>')
|
|
42
|
+
// 关键词
|
|
43
|
+
md = md.replace(/#keywords# (.*)/mg, '<div class="keywords">$1</div>')
|
|
44
|
+
// 摘要
|
|
45
|
+
md = md.replace(/#abstract# (.*)/mg, '<div class="abstract">$1</div>')
|
|
46
|
+
// 返回处理后的字符串
|
|
47
|
+
return md
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// preParseHTML
|
|
51
|
+
this.preParseHTML = (html: string): string => {
|
|
52
|
+
// 把包裹图片的 p 标签去掉
|
|
53
|
+
html = html.replace(/<p><img (.*?)><\/p>/g, '<img $1>')
|
|
54
|
+
// 加载字体
|
|
55
|
+
html = html.replace(/<\/head>/, `
|
|
56
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
57
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
58
|
+
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@200..900&display=swap" rel="stylesheet">
|
|
59
|
+
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@200..900&display=swap" rel="stylesheet">
|
|
60
|
+
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif:wght@200..900&display=swap" rel="stylesheet">
|
|
61
|
+
`)
|
|
62
|
+
return html
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// script
|
|
66
|
+
// 替换标点
|
|
67
|
+
if (zhPunctuation && !enPunctuation) {
|
|
68
|
+
this.script = () => {
|
|
69
|
+
const nodes = document.querySelectorAll('body > p, .abstract, .keywords, .author, .school')
|
|
70
|
+
nodes.forEach(node => {
|
|
71
|
+
let text = node.textContent ?? ''
|
|
72
|
+
// 替换中英文逗号和句号
|
|
73
|
+
text = text.replace(/, /g, ',').replace(/\. /g, '。').replace(/\.$/, '。')
|
|
74
|
+
// 替换中英文冒号
|
|
75
|
+
text = text.replace(/: /g, ':')
|
|
76
|
+
// 替换中英文分号
|
|
77
|
+
text = text.replace(/; /g, ';')
|
|
78
|
+
// 替换中英文感叹号
|
|
79
|
+
text = text.replace(/! /g, '!').replace(/!$/, '!')
|
|
80
|
+
// 替换中英文问号
|
|
81
|
+
text = text.replace(/\? /g, '?').replace(/\?$/, '?')
|
|
82
|
+
// 替换中英文括号
|
|
83
|
+
text = text.replace(/ \(/g, '(').replace(/\) /g, ')')
|
|
84
|
+
// 恢复et al.,
|
|
85
|
+
text = text.replace(/et al\.,/g, 'et al., ').replace(/et al。/g, 'et al. ')
|
|
86
|
+
// 设置新文本
|
|
87
|
+
node.textContent = text
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
} else if (!zhPunctuation && enPunctuation) {
|
|
91
|
+
this.script = () => {
|
|
92
|
+
const nodes = document.querySelectorAll('body > p, .abstract, .keywords, .author, .school')
|
|
93
|
+
nodes.forEach(node => {
|
|
94
|
+
let text = node.textContent ?? ''
|
|
95
|
+
// 替换中英文逗号和句号
|
|
96
|
+
text = text.replace(/,/g, ', ').replace(/。 /g, '. ')
|
|
97
|
+
// 替换中英文冒号
|
|
98
|
+
text = text.replace(/:/g, ': ')
|
|
99
|
+
// 替换中英文分号
|
|
100
|
+
text = text.replace(/;/g, '; ')
|
|
101
|
+
// 替换中英文感叹号
|
|
102
|
+
text = text.replace(/!/g, '! ')
|
|
103
|
+
// 替换中英文问号
|
|
104
|
+
text = text.replace(/?/g, '? ')
|
|
105
|
+
// 替换中英文括号
|
|
106
|
+
text = text.replace(/(/g, ' (').replace(/)/g, ') ')
|
|
107
|
+
// 设置新文本
|
|
108
|
+
node.textContent = text
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
this.script = () => {}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// pdfOptions
|
|
116
|
+
this.pdfOptions = {
|
|
117
|
+
format: 'A4',
|
|
118
|
+
margin: {
|
|
119
|
+
top: '2cm',
|
|
120
|
+
right: '2.5cm',
|
|
121
|
+
bottom: '2cm',
|
|
122
|
+
left: '2.5cm'
|
|
123
|
+
},
|
|
124
|
+
displayHeaderFooter: showTitle || !hideFooter,
|
|
125
|
+
headerTemplate: showTitle ? `<div style="font-size: 9px; font-family: 'SimSun'; color: #333; padding: 5px; margin-left: 0.6cm;"> <span class="title"></span> </div>` : `<div></div>`,
|
|
126
|
+
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>`,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
122
130
|
}
|