Skip to content

Commit

Permalink
bin/redcarpet: allow --<extension> options in ARGV
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaku committed Jan 23, 2012
1 parent f8897f9 commit 2a71813
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/redcarpet
@@ -1,16 +1,20 @@
#!/usr/bin/env ruby
# Usage: redcarpet [<file>...]
# Usage: redcarpet [--<extension>...] [<file>...]
# Convert one or more Markdown files to HTML and write to standard output. With
# no <file> or when <file> is '-', read Markdown source text from standard input.
# With <extension>s, perform additional Markdown processing before writing output.
if ARGV.include?('--help')
File.read(__FILE__).split("\n").grep(/^# /).each do |line|
puts line[2..-1]
end
exit 0
end

extensions = {}
ARGV.delete_if {|arg| if arg =~ /^--/ then extensions[$'.to_sym] = true end }

root = File.expand_path('../../', __FILE__)
$:.unshift File.expand_path('lib', root)

require 'redcarpet'
STDOUT.write(Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(ARGF.read))
STDOUT.write(Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions).render(ARGF.read))

0 comments on commit 2a71813

Please sign in to comment.