vscode编辑器markdow文档导出为pdf
1. vscode插件:Markdown Preview Enhanced
2. 在vscode内打开一个markdown文档
3. F1调出命令行,输入:Markdown Preview Enhanced: Extend Parser
4. 弹出的js文件内容替换成下面的代码:
function formatHead(markdown) { var seqNo = []; var mdArr = markdown.split("\n"); if (mdArr && mdArr.length > 0) { mdArr.forEach((element, i) => { var mat = element.match(/^(#+)\s+(\S.*)/); if (mat && mat.length > 2) { // 找到标题 var headseq = mat[1].length; for (var j = 1; j < headseq; j++) { if (seqNo.length < j) { seqNo.push(1); } } if (seqNo.length < headseq) { seqNo.push(1); } else { seqNo[headseq - 1] = seqNo[headseq - 1] + 1; if (seqNo.length > headseq) { seqNo.splice(headseq, seqNo.length - headseq); } } mdArr[i] = mat[1] + " " + seqNo.join(".") + " " + mat[2]; } }); } return mdArr.join("\n"); } module.exports = { onWillParseMarkdown: function(markdown) { return new Promise((resolve, reject)=> { markdown=formatHead(markdown); return resolve(markdown); }) }, onDidParseMarkdown: function(html) { return new Promise((resolve, reject)=> { return resolve(html) }) } }
5. markdown文档头部添加如下代码
--- export_on_save: puppeteer: true # export PDF on save ---
至此,大功告成。书写markdown文档后按保存按钮,会自动在同目录下生成一个同名的pdf文件
相关推荐
Yuezhilv 2020-04-25
Yvettre 2020-09-15
小焊猪web前端 2020-11-04
changcongying 2020-11-02
azhedashuaibi 2020-09-15
zhongfuyu 2020-08-16
lichuanlong00 2020-08-15
gsl 2020-08-15
mmwalker 2020-08-11
山有木兮卿有意 2020-08-03
Java编程语言学习 2020-07-29
举 2020-07-28
sshong 2020-07-19
fushilin 2020-07-05
80296630 2020-07-04
风雨断肠人 2020-06-14
ningningmingming 2020-06-14
hualala 2020-06-13
choupiaoyi 2020-06-13