Artifact Content
Not logged in

Artifact 498d2be9686d61b02e179be511174ad4060c1054:


#!/usr/bin/env ruby
require 'optparse'
require 'red_rug'

help_text = {
  escape:   'Escape all embedded HTML before parsing markdown.',
  help:     'Display this help text.',
  version:  'Display version and license information.'
}

@usage = <<-EOF

  USAGE: #{File.basename $0} [options] FILE

  This utility reads the contents of a Markdown formatted FILE, translates them
  to HTML, and prints the translated text to standard output.

EOF

version_help = <<-EOF

  RedRug #{RedRug.version}, Copyright 2012 Chad Perrin
  It may be distributed under the terms of the Open Works License.

EOF

options = Hash.new

OptionParser.new do |opts|
  opts.banner = @usage

  opts.on('--escape', '-e', help_text[:escape]) do
    options[:escape_html] = true
  end

  opts.on('--help', '-h', help_text[:help]) do
    puts opts
    puts
    exit(0)
  end

  opts.on_tail('--version', help_text[:version]) do
    puts version_help
    exit(0)
  end
end.parse!

content = String.new

$<.each {|line| content << line }

puts RedRug.to_html content, options