Skip to content

Instantly share code, notes, and snippets.

@joshnesbitt
Created January 13, 2012 09:22
Show Gist options
  • Save joshnesbitt/1605261 to your computer and use it in GitHub Desktop.
Save joshnesbitt/1605261 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'redcarpet'
require 'pathname'
path = Pathname.new(ARGV.shift)
raise "Input path must be absolute." unless path.absolute?
raise "Input path must point to a file that exists" unless path.exist?
raise "Input path must point to a file that is readable" unless path.readable?
output = Pathname.new(path.dirname.join(path.basename.sub(".md", ".html")))
engine = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
document = engine.render(path.read)
output.open("w") { |f| f.write(document) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment