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
My final solution was to use Python Markdown. I rolled my own extension that fixed the fence blocks.
Probably not what you want, but since you mentioned Node.js: I could not find a good tool to preview GitHub Flavored Markdown documentation on my local drive before committing them to GitHub, so today I created one, based on Node.js: https://github.com/ypocat/gfms
So perhaps you can reuse the showdown.js from it for your Wiki, if your question is still actual. If not, maybe other people facing the same problem as I did will find (just as I did) this question and this answer to it.
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:
#!/usr/bin/env ruby
HELP = <<-help
Usage: gfm [--readme | --plaintext] [<file>]
Convert a GitHub-Flavored Markdown file to HTML and write to standard output.
With no <file> or when <file> is '-', read Markdown source text from standard input.
With `--readme`, the files are parsed like README.md files in GitHub.com. By default,
the files are parsed with all the GFM extensions.
help
if ARGV.include?('--help')
puts HELP
exit 0
end
root = File.expand_path('../../', __FILE__)
$:.unshift File.expand_path('lib', root)
require 'github/markdown'
require 'tempfile'
require 'launchy'
mode = :gfm
mode = :markdown if ARGV.delete('--readme')
mode = :plaintext if ARGV.delete('--plaintext')
outputFilePath = File.join(Dir.tmpdir, File.basename(ARGF.path)) + ".html"
File.open(outputFilePath, "w") do |outputFile |
outputFile.write(GitHub::Markdown.to_html(ARGF.read, mode))
end
outputFileUri = 'file:///' + outputFilePath
Launchy.open(outputFileUri)
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.
I use Pandoc with the option --from=gfm
for GitHub Flavored Markdown like this:
$ pandoc my_file.md --from=gfm -t html -o my_file.html
Late addition but showdownjs has a CLI tool you can use to parse MD to HTML.