Created
March 28, 2013 22:32
-
-
Save funkaoshi/5267393 to your computer and use it in GitHub Desktop.
A simple script that takes a template, markdown file, and an optional foreword and spits out an HTML file.
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 ruby | |
require 'liquid' | |
require 'redcarpet' | |
if ARGV.length < 2 | |
puts "Usage: md2html <template> <markdown_doc> [markdown_foreword]" | |
exit | |
end | |
template = File.read(ARGV[0]) | |
document = File.read(ARGV[1]) | |
preamble = File.read(ARGV[2]) if ARGV.length > 2 | |
renderer = Redcarpet::Render::HTML.new(:with_toc_data => true) | |
markdown = Redcarpet::Markdown.new(renderer, :autolink => true, :space_after_headers => true, :tables => true) | |
tocgen = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC) | |
preamble = markdown.render(preamble) if preamble | |
contents = markdown.render(document) | |
toc = tocgen.render(document) | |
print Liquid::Template.parse(template).render('content' => contents, | |
'toc' => toc, | |
'preamble' => preamble, | |
'title' => "Philotomy's Musings") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is currently used to generate this page: Philotomy's Musings and a few other simple pages.