Skip to content

Instantly share code, notes, and snippets.

@funkaoshi funkaoshi/md2html.rb
Created Mar 28, 2013

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Mar 28, 2013

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
You can’t perform that action at this time.