forked from vmg/redcarpet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bin/redcarpet: allow --<extension> options in ARGV
- Loading branch information
Showing
1 changed file
with
6 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |