Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafYeeXYZ committed Jun 26, 2024
1 parent 0a69709 commit 119347b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

demo
论文.md

# Logs

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mdp
| 参数 | 说明 |
| :---: | :---: |
| `--out=xxx` | 输出文件相对路径<br>默认为源文件路径的同名 `PDF` 文件 |
| `--browser=xxx` | 浏览器绝对路径, 非 `Windows` 系统则必须<br>默认为 `C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe` |
| `--theme=xxx` | 论文模板, 默认为 `aps` (`Acta Psychologica Sinica`)<br>暂时没有其他模板, 欢迎贡献 |
| `--outputHTML` | 输出 `HTML` 文件, 默认不输出 |
| `--outputDOCX` | 输出 `DOCX` 文件, 默认不输出<br>**须先执行 `pip install pdf2docx` 安装依赖**<br>使用时推荐开启 `--hideFooter` 参数 |
Expand Down Expand Up @@ -68,6 +67,7 @@ mdp
```

## 更新日志
- `2.1.0` (2024-06-26): 支持 `MacOS` 系统, 改为在线加载字体
- `2.0.0` (2024-06-20): 重构代码, 完善模板功能
- `1.4.0` (2024-05-29): 新增替换中英文标点符号功能
- `1.3.2` (2024-05-28): 优化图表标题显示
Expand Down
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
13 changes: 2 additions & 11 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { marked } from 'marked'
import puppeteer from 'puppeteer-core'
import puppeteer from 'puppeteer'
import fs from 'node:fs/promises'
import path from 'node:path'
import { readFileSync } from 'node:fs'
Expand All @@ -12,8 +12,6 @@ export class Options {
src: string
/** pdf 文件绝对路径 */
out: string
/** 自定义浏览器 */
browser: string
/** 是否输出 html */
outputHTML: boolean
/** 是否输出 docx */
Expand Down Expand Up @@ -43,7 +41,6 @@ export class Options {
this.outputHTML = false
this.outputDOCX = false
this.theme = new APS(args, cwd)
this.browser = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'
// 解析路径参数
if (args.length === 0) throw SyntaxError()
else args[0] = `--src=${args[0]}`
Expand Down Expand Up @@ -83,12 +80,6 @@ export class Options {
this.outputDOCX = true
break
}
case '--browser': {
const a = arg.split('=')
if (a.length !== 2 || a[1] === '') throw SyntaxError()
this.browser = a[1]
break
}
}
})
// 检查参数
Expand Down Expand Up @@ -139,7 +130,7 @@ export async function renderMarkdown(options: Options): Promise<void> {
}
})
// 创建浏览器
const browser = await puppeteer.launch({ executablePath: options.browser })
const browser = await puppeteer.launch()
// 创建页面
const page = await browser.newPage()
// 设置页面内容
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "markdown-paper",
"type": "module",
"version": "2.0.0",
"version": "2.1.0",
"author": {
"name": "LeafYeeXYZ",
"email": "[email protected]"
Expand All @@ -10,7 +10,7 @@
"scripts": {
"mdp": "bun ./bin/mdp.ts",
"pub": "npm publish",
"try": "bun mdp ../../GoogleDrive/Curriculum/论文写作/论文.md --out=./demo/论文 --outputHTML"
"try": "bun mdp ./论文.md --out=./demo/论文 --outputHTML"
},
"bin": {
"mdp": "./bin/mdp.ts"
Expand All @@ -23,6 +23,6 @@
},
"dependencies": {
"marked": "^12.0.2",
"puppeteer-core": "^22.9.0"
"puppeteer": "^22.9.0"
}
}
31 changes: 17 additions & 14 deletions theme/aps/aps.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
* {
font-family: 'Times New Roman', '宋体'; /* 所有数字和英文字体都用 Times New Roman */
font-family: 'Noto Serif', 'Noto Serif SC'; /* 所有数字和英文字体都用 Times New Roman */
line-height: 1.55em; /* 1.5倍行距 */
margin: 0;
}

h1 { /* 中文题目: 二号黑体 */
font-size: 29px;
font-weight: normal;
font-family: '黑体';
font-weight: 500;
font-family: 'Noto Sans SC';
text-align: center;
margin-bottom: 9px;
}
.author { /* 作者姓名: 四号仿宋 */
font-size: 18px;
font-family: '仿宋';
font-weight: 300;
font-family: 'Noto Serif SC';
text-align: center;
margin-bottom: 3px;
}
Expand All @@ -28,7 +29,8 @@ h1 { /* 中文题目: 二号黑体 */
padding: 0 28px;
&::before {
content: '摘 要';
font-family: '黑体';
font-weight: 500;
font-family: 'Noto Sans SC';
display: inline-block;
margin-right: 14px;
}
Expand All @@ -39,7 +41,8 @@ h1 { /* 中文题目: 二号黑体 */
padding: 0 28px;
&::before {
content: '关键词';
font-family: '黑体';
font-weight: 500;
font-family: 'Noto Sans SC';
display: inline-block;
margin-right: 14px;
}
Expand All @@ -52,14 +55,14 @@ h2 { /* 一级标题: 四号宋体 */
}
h3 { /* 二级标题: 五号黑体 */
font-size: 14px;
font-weight: normal;
font-family: '黑体';
font-weight: 500;
font-family: 'Noto Sans SC';
margin: 5px 0;
}
h4 { /* 三级标题: 五号黑体 */
font-size: 14px;
font-weight: normal;
font-family: '黑体';
font-weight: 500;
font-family: 'Noto Sans SC';
margin: 3px 0;
}

Expand All @@ -71,8 +74,8 @@ p { /* 正文: 五号宋体 */

h5 { /* "参考文献": 五号黑体 */
font-size: 14px;
font-weight: normal;
font-family: '黑体';
font-weight: 500;
font-family: 'Noto Sans SC';
text-align: center;
margin-bottom: 7px;
margin-top: 20px;
Expand Down Expand Up @@ -129,6 +132,6 @@ table { /* 表格: 小五号宋体 */
}

b, strong { /* 加粗按黑体处理 */
font-family: '黑体';
font-weight: normal;
font-weight: 500;
font-family: 'Noto Sans SC';
}
14 changes: 11 additions & 3 deletions theme/aps/aps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ export class APS extends Theme {
}

// preParseHTML
// 把包裹图片的 p 标签去掉
this.preParseHTML = (html: string): string => {
// 把包裹图片的 p 标签去掉
html = html.replace(/<p><img (.*?)><\/p>/g, '<img $1>')
// 加载字体
html = html.replace(/<\/head>/, `
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:[email protected]&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:[email protected]&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif:[email protected]&display=swap" rel="stylesheet">
`)
return html
}

Expand Down Expand Up @@ -114,8 +122,8 @@ export class APS extends Theme {
left: '2.5cm'
},
displayHeaderFooter: showTitle || !hideFooter,
headerTemplate: showTitle ? `<div style="font-size: 9px; font-family: '宋体'; color: #333; padding: 5px; margin-left: 0.6cm;"> <span class="title"></span> </div>` : `<div></div>`,
footerTemplate: hideFooter ? `<div></div>` : `<div style="font-size: 9px; font-family: '宋体'; color: #333; padding: 5px; margin: 0 auto;">第 <span class="pageNumber"></span> 页 / 共 <span class="totalPages"></span> 页</div>`,
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>`,
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>`,
}

}
Expand Down

0 comments on commit 119347b

Please sign in to comment.