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 con
Maybe this might help:
gem install github-markdown
No documentation exists, but I got it from the gollum documentation. Looking at rubydoc.info, it looks like you can use:
require 'github/markdown'
puts GitHub::Markdown.render_gfm('your markdown string')
in your Ruby code. You can wrap that easily in a script to turn it into a command line utility:
#!/usr/bin/env ruby
# render.rb
require 'github/markdown'
puts GitHub::Markdown.render_gfm File.read(ARGV[0])
Execute it with ./render.rb path/to/my/markdown/file.md
. Note that this is not safe for use in production without sanitization.
This is mostly a follow-on to @barry-staes's answer for using Pandoc. Homebrew has it as well, if you're on a Mac:
brew install pandoc
Pandoc supports GFM as an input format via the markdown_github
name.
Output to file
cat foo.md | pandoc -f markdown_github > foo.html
Open in Lynx
cat foo.md | pandoc -f markdown_github | lynx -stdin # To open in Lynx
Open in the default browser on OS X
cat foo.md | pandoc -f markdown_github > foo.html && open foo.html # To open in the default browser on OS X`
TextMate Integration
You can always pipe the current selection or current document to one of the above, as most editors allow you to do. You can also easily configure the environment so that pandoc
replaces the default Markdown processor used by the Markdown bundle.
First, create a shell script with the following contents (I'll call it ghmarkdown
):
#!/bin/bash
# Note included, optional --email-obfuscation arg
pandoc -f markdown_github --email-obfuscation=references
You can then set the TM_MARKDOWN
variable (in Preferences→Variables) to /path/to/ghmarkdown
, and it will replace the default Markdown processor.
I recently made what you want, because I was in need to generate documentation from Markdown files and the GitHub style is pretty nice. Try it. It is written in Node.js.
gfm
I found a website that will do this for you: http://tmpvar.com/markdown.html. Paste in your Markdown, and it'll display it for you. It seems to work just fine!
However, it doesn't seem to handle the syntax highlighting option for code; that is, the ~~~ruby
feature doesn't work. It just prints 'ruby'.
Building on this comment I wrote a one-liner to hit the Github Markdown API using curl
and jq
.
Paste this bash function onto the command line or into your ~/.bash_profile
:
mdsee(){
HTMLFILE="$(mktemp -u).html"
cat "$1" | \
jq --slurp --raw-input '{"text": "\(.)", "mode": "markdown"}' | \
curl -s --data @- https://api.github.com/markdown > "$HTMLFILE"
echo $HTMLFILE
open "$HTMLFILE"
}
And then to see the rendered HTML in-browser run:
mdsee readme.md
Replace open "$HTMLFILE"
with lynx "$HTMLFILE"
if you need a pure terminal solution.
There is a really nice and simple tool for browsing GFM Markdown documents:
GFMS - Github Flavored Markdown Server
It's simple and lightweight (no configuration needed) HTTP server you can start in any directory containing markdown files to browse them.
Features: