写作vscode使用

2.4 vscode + MPE + pandoc 处理 off

2019-10-17  本文已影响0人  水之心

本章导航:

  1. 介绍 pandoc 处理 office 文档的基本语法。

5.1 安装 pandoc

更多内容可以参考资源:markdown 转 docx 及 pdf 转 docx|MPE

5.2 在 vscode 中使用 pandoc 导出 word

如何需要将 markdown 导出为 word,那么,您可以设置如下:

---
title: 构建属于自己的项目
author: xinetzone
date: 2019/10/17
output:
  word_document:
    highlight: "tango"
---

其中 highlight 用于设置代码的高亮的主题。上面的设置便可以输出一个十分美观的 word 版本的文档。下图对比代码高亮与不高亮的区别:

图5.1 代码高亮对比

图5.1 的左边是代码没有高亮的,而右边是代码高亮的。两者的优劣一眼便可看出。

这里的高亮主题可以选择 zenburn 来获取更好的观感体验:

图5.2 高亮主题设置为 `zenburn`

5.2.1 依据给定的模板输出 word 文档

有时,我们想要依据给定的模板 mystyles.docx 来输出 word 文档,您可以这样设置:

---
title: 构建属于自己的项目
author: xinetzone
date: 2019/10/17
output:
  word_document:
    highlight: "tango"
    reference_doc: mystyles.docx
---

5.2.2 设置多文件生成 word 的模板

如果想要在同一个文件夹下的 markdown 文档以相同的模板生成 word 文档,您可以在该目录下设置文件 _output.yaml 并输入模板配置,比如:

word_document:
  highlight: zenburn

这样,您不必在 markdown 中再次设置上述参数,即可达到设置 _output.yaml 中参数的效果。

5.2.3 设置自动目录

如果需要设置自动目录,可以这样:

---
title: 构建属于自己的项目
author: xinetzone
date: 2019/10/17
output:
  word_document:
    highlight: zenburn
    reference_doc: mystyles.docx
    toc: true
    toc_depth: 2
---

5.2.4 自动导出为 word

如果您不想每次都在预览 markdown 的时候,手动生成 word,您可以设置 export_on_save 自动生成 word:

---
output: word_document
export_on_save:
  pandoc: true
---

5.3 pandoc 转换为 pdf 等文档

如果存在中文,最好使用命令行的形式生成 pdf 等文档。比如:

front-matter 输入:

---
title: 构建属于自己的项目
author: xinetzone
date: 2019/10/17
output: 
   beamer_presentation:
      incremental: true
      theme: "AnnArbor"
      colortheme: "dolphin"
      fonttheme: "structurebold"
      highlight: tango
      slide_level: 2
      toc: true
---

命令行输入:

$ pandoc k.md -o k.pdf -V CJKmainfont=KaiTi --pdf-engine=xelatex
上一篇下一篇

猜你喜欢

热点阅读