Last active
December 23, 2015 19:09
-
-
Save jonlabelle/6680398 to your computer and use it in GitHub Desktop.
A simple Sublime Text Build System for Markdown source.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Sublime Text 2|3 Markdown Build System | |
# | |
# This Sublime Text 2|3 build system simply takes Markdown source as an | |
# arg(1) and parses the HTML for previewing in a browser window. | |
# | |
# **Requirements** | |
# | |
# - Sublime Text 3 <http://www.sublimetext.com> | |
# - Python-Markdown <http://pythonhosted.org/Markdown> | |
# - OSX and Safari|Chrome|FF | |
# | |
# Jon LaBelle <jon@tech0.com> | |
# | |
# Usage | |
# ----- | |
# | |
# 1. Create a `~/bin` and `~/tmp` directory. | |
# | |
# $ mkdir -p ~/tmp # where html file is generated | |
# $ mkdir -p ~/bin # where this script will live. | |
# | |
# 2. Create the Build System | |
# | |
# - Open Sublime Text and from `Tools` > `Build System` select ß | |
# New Build System...` | |
# | |
# - Replace the auto-generated JSON with the following: | |
# | |
# { | |
# "cmd": ["mdpreview", "$file"], | |
# "path": "$PATH:$HOME/bin", | |
# "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", | |
# "selector": "source.markdown" | |
# } | |
# | |
# - Save the Build System in `User` directory as: | |
# | |
# ../Packages/User/Markdown.sublime-build' | |
# | |
# 3. Finally, put this script to your `~/bin` and make it executable. | |
# | |
# $ mv mdpreview.sh ~/bin/mdpreview | |
# $ chmod +x ~/bin/mdpreview | |
# | |
# That's it! | |
# | |
# Use the shortcut key `CMD + B` to run the build. | |
# | |
# Python-Markdown Built-in Extensions | |
# ----------------------------------- | |
# | |
# [-x 'extra'] | |
# imitates `PHP Markdown Extra`. | |
# | |
# [-x 'nl2br'] | |
# treat newlines as hard breaks. | |
# | |
# [-x 'codehilite'] | |
# code/syntax highlighting using `Pygments`. | |
# | |
# [-x 'sane_lists'] | |
# does not allow the mixing of list types. | |
# | |
# [-x 'toc'] | |
# adds a table of contents to the document. | |
# | |
# [-x 'headerid'] | |
# generates `id` attrib for (h1-h6). | |
# | |
# [-x 'wikilinks'] | |
# any `[[bracketed]]` word is converted to a link. | |
# | |
# | |
# Python-Markdown Third-party Extensions | |
# -------------------------------------- | |
# | |
# [-x 'del_ins'] | |
# adds support <del> and <ins> tags. | |
# - <ins> "++added content++" </ins> | |
# - <del> "~~deleted content~~" </del> | |
# | |
# [-x 'cite'] | |
# adds support for <cite> tag. | |
# - <cite> """Who Is Killing the Great Chefs of Europe?""" </cite> | |
# | |
# Python-Markdown Resources | |
# ------------------------- | |
# | |
# - [Python-Markdown](http://pythonhosted.org/Markdown/siteindex.html) | |
# - [Using Python-Markdown on the Command Line](http://pythonhosted.org/Markdown/cli.html) | |
# - [Python-Markdown Extensions](http://pythonhosted.org/Markdown/extensions) | |
# - [Python-Markdown 3rd-Party Extensions](https://github.com/waylan/Python-Markdown/wiki/Third-Party-Extensions) | |
# | |
MDPREVIEWFILE="${HOME}/tmp/`basename ${0}`.html" | |
python -m markdown "${1}" -f "${MDPREVIEWFILE}" \ | |
-o "html5" \ | |
-x "extra" \ | |
-x "nl2br" \ | |
-x "toc" \ | |
-x "sane_lists" \ | |
-x "wikilinks" \ | |
-x "del_ins" \ | |
-x "cite" \ | |
-x "headerid(forceid=False)" \ | |
-x "codehilite(linenums=False,guess_lang=True)" | |
open -a "Safari" "${MDPREVIEWFILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment