@lumincinta
2017-01-31T16:18:54.000000Z
字数 8133
阅读 336
SublimePlugin Markdown
Sublime Text 2/3 Markdown Preview
Preview and build your markdown files quickly in your web browser from sublime text 2/3.
You can use builtin python-markdown parser or use the github markdown API for the conversion.
NOTE: If you choose the GitHub API for conversion (set parser: github in your settings), your code will be sent through https to github for live conversion. You'll have Github flavored markdown, syntax highlighting and EMOJI support for free :heart: :octocat: :gift:. If you make more than 60 calls a day, be sure to set your GitHub API key in the settings :). You can also get most of this in the default Markdown parser with by enabling certain extensions; see "Parsing Github Flavored Markdown"" below for more information.
LINUX users: If you want to use GitHub API for conversion, you'll need to have a custom Python install that includes python-ssl as its not built in the Sublime Text 2 Linux package. see @dusteye comment. If you use a custom window manager, also be sure to set a BROWSER environment variable. see @PPvG comments
"parser" config.abbr, attr_list, def_list, fenced_code, footnotes, tables, smart_strong, smarty, wikilinks, meta, sane_lists, codehilite, nl2br, and toc markdown extensions.enable_mathjax to true in your settings. MathJax is then downloaded in the background so you need to have an internet access.3rd party extensions for the Python Markdown parser:
| Extension | Documentation |
|---|---|
| magiclink | Find and convert HTML links and email address to links (MagicLink Documentation). |
| delete | Surround inline text with to get del tags |
| insert | Surround inline text with ^^underlined^^ to get ins tags underlined. |
| tasklist | Github Flavored Markdown tasklists (Tasklist Documentation). |
| githubemoji | Support for Github Flavored Markdown emojis (GithubEmoji Documentation). |
| headeranchor | Github Flavored Markdown style header anchors (HeaderAnchor Documentation). |
| github | A convenience extension to add: magiclink, delete, tasklist, githubemoji, headeranchor, superfences, and nl2br to parse and display Markdown in a github-ish way. It is recommed to pair github with extra and codehilite (with language guessing off) to parse close to github's way. Be aware of what extensions github loads, because you should not load extensions more than once. |
| progressbar | Create progress bars (ProgressBar Documentation). |
| superfences | Allow fenced blocks to be nested under lists, blockquotes, etc. and add special UML diagram blocks (SuperFences Documentation). |
For all Sublime Text 2/3 users we recommend install via Package Control.
Package Control: Install PackageMarkdown Preview and install it.Preferences > Browse Packages… menuInstalled Packages/ folderMarkdown Preview.sublime-package and copy it into the Installed Packages/ directoryMarkdown Preview to show the follow commands (you will be prompted to select which parser you prefer): { "keys": ["alt+m"], "command": "markdown_preview", "args": {"target": "browser", "parser":"markdown"} }, for a specific parser and target or { "keys": ["alt+m"], "command": "markdown_preview_select", "args": {"target": "browser"} }, to bring up the quick panel to select enabled parsers for a given target.External parser commands and arguments should first be mapped to a name. The path to the binary should be first, followed by flags etc.
"markdown_binary_map": {"multimarkdown": ["/usr/local/bin/multimarkdown"]},
Then the name can be placed in enabled_parsers to enable use of the new parser.
"enabled_parsers": ["markdown", "github", "multimarkdown"],
Using Sublime Text menu: Preferences->Package Settings->Markdown Preview
Settings - User is where you change your settings for Markdown Preview.Settings - Default is a good reference with detailed descriptions for each setting.If you add the codehilite extension manually in the enabled extensions, you can override some of the default settings.
codehilite(guess_lang=False) (True|False).codehilite(linenums=True) (True|False).codehilite(pygments_style=emacs).codehilite(noclasses=True) (True|False).codehilite(linenums=True, pygments_style-emacs).See codehilte page for more info.
When the meta extension is enabled (https://pythonhosted.org/Markdown/extensions/meta_data.html), the results will be written to the HTML head in the form <meta name="key" content="value1,value2">. title is the one exception, and its content will be written to the title tag in the HTML head.
YAML frontmatter can be stripped out and read when strip_yaml_front_matter is set to true in the settings file. In general the, the fronmatter is handled the same as meta data, but if both exist in a file, the YAML keys will override the meta extension keys. There are a few special keys names that won't be handled as html meta data.
Yaml frontmatter has a few special key names that are used that will not be handled as meta data:
basepath setting.Save to HTML command. Relative paths first use the source file's directory, and if the file cannot be found, it will use the basepath setting.
---# Builtin valuesreferences:- references.md- abbreviations.md- footnotes.mddestination: destination.html# Meta Datatitle: Test Pageauthor:- John Doe- Jane Doe# Settings overridessettings:enabled_extensions:- extra- github- toc- headerid- smarty(smart_quotes=False) # smart quotes interferes with attr_list- meta- wikilinks- admonition- codehilite(guess_lang=False,pygments_style=github)---
Github Flavored Mardown (GFM) is a very popular markdown. Markdown Preview can actually handle them in a couple of ways: online and offline.
Parsing GFM using the online method requires using the Github API as the parser. It may also require setting github_mode to gfm to get things like tasklists to render properly. You can set your API key in the settings as follows:
"github_oauth_token": "secret"
By default almost all extensions are enabled to help with the github feel, but there are some tweaks needed to get the full experience.
GFM does not auto guess language in fenced blocks, but Markdown Preview does this by default. You can fix this in one of two ways:
"guess_language": false,"enabled_extensions": ["codehilite(guess_lang=False,pygments_style=github)"]As mentioned earlier, almost all extensions are enabled by default, but as a reference, the minimum extensions that should be enabled are listed below:
"enabled_extensions": ["extra","github","codehilite(guess_lang=False,pygments_style=github)"]
This may be further enhanced in the future.
The code is available at github project under MIT license.