Skip to content

Instantly share code, notes, and snippets.

@hongyangqin
Last active December 1, 2017 14:33
Show Gist options
  • Select an option

  • Save hongyangqin/db90a23b5413813dec155ec6b6af36e3 to your computer and use it in GitHub Desktop.

Select an option

Save hongyangqin/db90a23b5413813dec155ec6b6af36e3 to your computer and use it in GitHub Desktop.

[CodeEdit--Sublime]写支持Pandoc扩展的markdown文档

简述

在Sublime中配置好了写支持Pandoc扩展语法的markdown文档。可以看到写markdown时有语法高亮,而且写完后可以直接通过命令转换成想要的格式(目前主要在用html和pdf)。

配置过程

首先当然是要确认已经安装了package control,我早前已经安装好,其安装方法网络搜索一下,就有许多的参考。
然后安装Monokai Extended插件,MarkdownEditing插件,MarkdownTOC插件,Pandoc插件(Pandoc软件也需要首先先安装好)。如果要转换pdf,还要安装LaTex软件。

如何使用

新建.md的markdown文档后在sublime中打开,在软件右下角的文档格式选择为Markdown Extended。
这里写图片描述
这样就能够看到markdown语法高亮了。

接下来要配置Pandoc插件,如下是几分配置文件参考示例:

{
// There are 2 possible top level settings keys, "user" and "default". If you
// use "default" in your user settings file, the default settings will be
// overwritten, but if you use "user" your settings will be merged into the
// default settings.
"default": {
// path to the pandoc binary. Default locations per platform:
// -  mac
//    "pandoc-path": "/usr/local/bin/pandoc",
// -  windows
//    "pandoc-path": "C:/Users/[username]/AppData/Local/Pandoc/pandoc.exe",
"pandoc-path": null,
// transformations
"transformations": {
// label of transformation, to appear in sublime quick panel. This should
// be a name related to the format of the output.
"Markdown (Pandoc)": {
// Opens output in new buffer (instead of replacing input in same buffer)
"new-buffer": 1,
// maps sublime scope to input format. If the input matches against the
// given scope, this transformation becomes available, and the input
// format is used as the pandoc --from option.
// @see http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html#scopes
// @see score_selector() http://www.sublimetext.com/docs/3/api_reference.html
// @see http://johnmacfarlane.net/pandoc/README.html#options
"scope": {
  "text.html": "html"
},
// sublime syntax file of output format, will set output to this syntax
"syntax_file": "Packages/Markdown/Markdown.tmLanguage",
// additional arguments passed to pandoc
// -  --from is automatically set, see "scope" above
// -  --to=FORMAT or one of its aliases is required
// @see http://johnmacfarlane.net/pandoc/README.html#options
"pandoc-arguments": [
  "--to=markdown",
  "--wrap=none",
  "--atx-headers"
]
},
"HTML 5": {
"new-buffer": 1,
"scope": {
  "text.html.markdown": "markdown"
},
"syntax_file": "Packages/HTML/HTML.tmLanguage",
"pandoc-arguments": [
  "--to=html5",
  "--no-highlight"
]
},
// note these are examples of output formats that should not be opened in a
// sublime text buffer. See "pandoc-format-file" below
// @see http://johnmacfarlane.net/pandoc/README.html#creating-a-pdf
"PDF": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown"
},
// use to place the output in the same directory as the curent file
// if -o or --output are set in "pandoc-arguments" this is ignored
// "out-local": true,
"pandoc-arguments": [
  "-t", "pdf"
  // use --latex-engine=engine where engine is
  // pdflatex|lualatex|xelatex. This may need to be specified with a
  // full path, e.g. on a mac with BasicTeX
  // "--latex-engine=/usr/texbin/pdflatex"
  // or on Windows with MiKTeX
  // "--latex-engine=C:/Program Files (x86)/MiKTeX 2.9/miktex/bin/pdflatex.exe"
  // if -o or --output missing, will write to a temporary file
  // "--output=~/Downloads/output.pdf"
]
},
"Microsoft Word": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown"
},
"pandoc-arguments": [
  "-t", "docx"
  // if -o or --output missing, will write to a temporary file
  // "--output=~/Downloads/output.pdf"
]
},
"PDF TOC (Narrow margins)": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown",
  },
"pandoc-arguments": [
  "-V", "geometry:margin=1.25in",
  "-s", "--toc", "--number-sections", "--parse-raw",
  "-t", "pdf",
],
},
"PDF TOC": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown",
  },
"pandoc-arguments": [
  "-s", "--toc", "--number-sections", "--parse-raw",
  "-t", "pdf",
 ],
},
"HTML TOC": {
"new-buffer": 1,
"scope": {
  "text.html.markdown": "markdown"
},
"syntax_file": "Packages/HTML/HTML.tmLanguage",
"pandoc-arguments": [
  "--to=html5",
  "--no-highlight",
  "-s", "--toc"
]
},
"Beamer Slides (PDF)": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown",
},
// Use the "out-ext" parameter to define a custom output file extension. Commonly used for pdf.
"out-ext": "pdf",
"pandoc-arguments": [
  "-t", "beamer",
  "--latex-engine=C:/Program Files (x86)/MiKTeX 2.9/miktex/bin/pdflatex.exe"
]
},
"Beamer Slides (LaTeX)": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown",
},
"pandoc-arguments": [
  "-t", "beamer",
]
},
"s5 Slides": {
"scope": {
  "text.html": "html",
  "text.html.markdown": "markdown",
},
"pandoc-arguments": [
  "-t", "slidy", "-s", "--self-contained",
]
},
},
// these should not need to be customized
// output formats that are written to file, using -o parameter. These we do
// not output to a sublime text buffer.
"pandoc-format-file": ["docx", "epub", "pdf", "odt", "beamer"]
}
}
{
  "default": {
    "pandoc-path": "C:/Program Files (x86)/Pandoc",
    "transformations": {
      "HTML": {
	"scope": {
	  "text.html": "html",
	  "text.html.markdown": "markdown"
},
"pandoc-arguments": [
  "-o"
]
},
"PDF": {
"scope": {
"text.html": "html",
"text.html.markdown": "markdown"
},
"pandoc-arguments": [
"-t", "pdf", **"--latex-engine=/usr/texbin/pdflatex"**,
**"--filter=/usr/local/bin/pandoc-citeproc"**,
**"--bibliography=/Users/frank/Documents/Mendeley/reference.bib"**
]
},
"Microsoft Word": {
"scope": {
"text.html": "html",
"text.html.markdown": "markdown"
},
"pandoc-arguments": [
"-t", "docx",
**"--filter=/usr/local/bin/pandoc-citeproc"**,
**"--bibliography=/Users/frank/Documents/Mendeley/reference.bib"**
]
}
},
"pandoc-format-file": ["html", "docx", "epub", "pdf", "odt"]
}
}
{
// Sets the path to the pandoc binary.
"pandoc-path": null,
// Opens output in new buffer (instead of replacing input in same)
"new-buffer": 1,
// configure Pandoc executable
// see http://johnmacfarlane.net/pandoc/README.html#options
// enabled Pandoc formats
// key: label, value: Pandoc format key (-f or -t values)
"formats": {
"AsciiDoc": "asciidoc",
"LaTeX beamer slide show": "beamer",
"ConTeXt": "context",
"DocBook XML": "docbook",
"Word docx": "docx",
"HTML5 + javascript slide show": "dzslides",
"EPUB v2": "epub",
"EPUB v3": "epub3",
"FictionBook2 e-book": "fb2",
"Haddock": "haddock",
"XHTML 1": "html",
"HTML 5": "html5",
"JSON version of native AST": "json",
"LaTeX": "latex",
"Groff man": "man",
"Markdown": "markdown",
"Markdown (Github extended)": "markdown_github",
"Markdown (PHP Markdown Extra extended)": "markdown_phpextra",
"Markdown (Strict)": "markdown_strict",
"MediaWiki markup": "mediawiki",
"Native Haskell": "native",
"OpenOffice text document": "odt",
"OpenDocument XML": "opendocument",
"OPML": "opml",
"Emacs Org-Mode": "org",
"PDF": "pdf",
"reveal.js HTML5 + javascript slide show": "revealjs",
"Rich Text Format": "rtf",
"plain text": "plain",
"reStructuredText": "rst",
"S5 HTML and javascript slide show": "s5",
"Slideous HTML and javascript slide show": "slideous",
"Slidy HTML and javascript slide show": "slidy",
"GNU Texinfo": "texinfo",
"Textile": "textile"
},
// format configuration
// key: format_[key] where [key] is the Pandoc format key (-f or -t values)
// - scope: input sublime scope. Missing implies pandoc can not accept the
//   format as input (@todo fix this, allow multiple input formats per scope)
// - syntax_file: sublime syntax file of output format, will set output to
//   this syntax
// - from: list of pandoc options to add when used as input
// - to: list of pandoc options to add when used as output
"format_asciidoc": {},
"format_beamer": {
"syntax_file": "Packages/LaTeX/LaTeX Beamer.tmLanguage"
},
"format_context": {
"syntax_file": "Packages/LaTeX/LaTeX.tmLanguage"
},
"format_docbook": {
// "scope": "text.xml",
"syntax_file": "Packages/XML/XML.tmLanguage"
},
"format_docx": {},
"format_dzslides": {
"syntax_file": "Packages/HTML/HTML.tmLanguage"
},
"format_epub": {
"syntax_file": "Packages/XML/XML.tmLanguage"
},
"format_epub3": {
"syntax_file": "Packages/XML/XML.tmLanguage"
},
"format_fb2": {},
"format_haddock": {},
"format_html": {
"scope": "text.html",
"syntax_file": "Packages/HTML/HTML.tmLanguage"  },
"format_html5": {
"syntax_file": "Packages/HTML/HTML.tmLanguage"  },
"format_json": {
"scope": "source.json",
"syntax_file": "Packages/JavaScript/JSON.tmLanguage"
},
"format_latex": {
"scope": "text.tex.latex",
"syntax_file": "Packages/LaTeX/LaTeX.tmLanguage"
},
"format_man": {},
// pandoc by default uses an enhanced version of markdown, see
// http://johnmacfarlane.net/pandoc/README.html#pandocs-markdown
// to disable:
//    -   pandoc <1.10: add "--strict" to "to" or "from"
//    -   pandoc >=1.10: use markdown_strict output format
"format_markdown": {
"scope": "text.html.markdown",
"syntax_file": "Packages/Markdown/Markdown.tmLanguage",
"to": ["--no-wrap", "--atx-headers"],
"from": ["--no-highlight"]
},
"format_markdown_github": {
// "scope": "text.html.markdown",
"syntax_file": "Packages/Markdown/Markdown.tmLanguage"
},
"format_markdown_phpextra": {
// "scope": "text.html.markdown",
"syntax_file": "Packages/Markdown/Markdown.tmLanguage"
},
"format_markdown_strict": {
// "scope": "text.html.markdown",
"syntax_file": "Packages/Markdown/Markdown.tmLanguage"
},
"format_mediawiki": {
"scope": "text.html.mediawiki",
"syntax_file": "Packages/Mediawiker/Mediawiki.tmLanguage"
},
"format_native": {
"scope": "source.haskell",
"syntax_file": "Packages/Haskell/Haskell.tmLanguage"
},
"format_odt": {},
"format_opendocument": {
"syntax_file": "Packages/XML/XML.tmLanguage"
},
"format_pdf": {
// use --latex-engine=engine where engine is one of pdflatex|lualatex|xelatex
// This may need to be specified with a full path (e.g. on a mac with
// BasicTeX "/usr/texbin/pdflatex").
"to": ["--latex-engine=/usr/texbin/pdflatex"]
},
"format_rtf": {},
"format_opml": {
// "scope": "text.xml",
"syntax_file": "Packages/XML/XML.tmLanguage"
},
"format_org": {},
"format_plain": {
"syntax_file": "Packages/Text/Plain text.tmLanguage"
},
"format_revealjs": {
"syntax_file": "Packages/HTML/HTML.tmLanguage"
},
"format_rst": {
"scope": "text.restructuredtext",
"syntax_file": "Packages/RestructuredText/reStructuredText.tmLanguage"
},
"format_s5": {
"syntax_file": "Packages/HTML/HTML.tmLanguage"
},
"format_slideous": {
"syntax_file": "Packages/HTML/HTML.tmLanguage"
},
"format_slidy": {
"syntax_file": "Packages/HTML/HTML.tmLanguage"
},
"format_texinfo": {
"syntax_file": "Packages/LaTeX/LaTeX Beamer.tmLanguage"
},
"format_textile": {
"scope": "text.html.textile",
"syntax_file": "Packages/Textile/Textile.tmLanguage"
}
}

我这里选择了第一种配置,在写完了markdown文档后,用Ctrl + Shift + P调出package control,然后输入Pandoc,选择Pandoc插件,会弹出如下的界面:
这里写图片描述
就可以选择要转换的格式,我这里选择了带目录的html格式–HTML TOC,然后会生成对应的html文档并自动在sublime中打开,转换其他格式的文档也是类似流程。

参考文章

这篇很不错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment