[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中打開,轉換其他格式的文檔也是類似流程。

參考文章

這篇很不錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章