I'm wondering if there is a command line utility for taking a GitHub flavored Markdown file and rendering it to HTML.
I'm using a GitHub wiki to create website content. I've cloned the repository on my server and would then like to process it into regular HTML. It's important to me that what appears on GitHub is exactly how it should look for my website. I'd also really like to use the fenced blocks with ~~~
, so I'd rather not use standard Markdown syntax only.
I've looked a bit into the JavaScript live preview thinking I could hook it into Node.js, but they say it is deprecated. I've looked at the redcarpet repository, but it doesn't look like it has a command line interface.
I rolled my own solution, however, since no solution here is clearly better than the others, I'll leave the question without a selected answer.
I created a tool similar to Atom's Preview functionality, but as a standalone application. Not sure if this is what you're looking for, but it might be helpful. -- https://github.com/yoshuawuyts/vmd
I wrote a small CLI in Python and added GFM support. It's called Grip (Github Readme Instant Preview).
Install it with:
And to use it, simply:
Then visit
localhost:5000
to view thereadme.md
file at that location.You can also specify your own file:
And change port:
And of course, specifically render GitHub-Flavored Markdown, optionally with repository context:
Notable features:
stdin
and export tostdout
added in 3.0Hope this helps someone here. Check it out.
I use Pandoc with the option
--from=gfm
like this:Based on Jim Lim's answer, I installed the GitHub Markdown gem. That included a script called gfm that takes a filename on the command line and writes the equivalent HTML to standard output. I modified that slightly to save the file to disk and then to open the standard browser with launchy:
GitHub has (since) developed a nice modular text editor called Atom (based on Chromium and uses Node.js modules for packages).
A default preinstalled package Markdown Preview lets you display your preview in a separate tab using Ctrl + Shift + M.
I haven't tested its full syntax, but since it's coming from GitHub, I'd be highly surprised if the preview's syntax was different from theirs (fenced blocks using
~~~
work).Now, while it's not technically command-line based, it uses Node.js and outputs to a DOM-based renderer, which might help anyone trying to render GitHub syntax-based HTML on a Node.js-based webserver, or just edit her/his README.md offline.
Building on this comment I wrote a one-liner to hit the Github Markdown API using
curl
andjq
.Paste this bash function onto the command line or into your
~/.bash_profile
:And then to see the rendered HTML in-browser run:
Replace
open "$HTMLFILE"
withlynx "$HTMLFILE"
if you need a pure terminal solution.