Skip to content

Instantly share code, notes, and snippets.

@funkaoshi
Created March 28, 2013 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkaoshi/5267393 to your computer and use it in GitHub Desktop.
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.
#!/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")
@funkaoshi
Copy link
Author

This is currently used to generate this page: Philotomy's Musings and a few other simple pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment