just use the pygments.appspot.com if there's no pygmentize on the path, rather than as a command line flag

This commit is contained in:
Burke Libbey 2010-03-30 13:46:24 -05:00
parent bc8bdccb7d
commit fb4b5404ae
2 changed files with 6 additions and 9 deletions

View File

@ -7,10 +7,6 @@
#/ -c, --comment-chars=<chars>
#/ The string to recognize as a comment marker
#/ -o, --output=<dir> Directory where generated HTML files are written
#/ -w Highlight code using http://pygments.appspot.com
#/ instead of pygmentize(1)
#/
#/
#/ --help Show this help message
require 'optparse'
@ -40,7 +36,6 @@ ARGV.options { |o|
o.on("-o", "--output=DIR") { |dir| output_dir = dir }
o.on("-l", "--language=LANG") { |lang| options[:language] = lang }
o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) }
o.on("-w") { |v| options[:webservice] = v }
o.on_tail("-h", "--help") { usage($stdout, 0) }
o.parse!
} or abort_with_note

View File

@ -75,7 +75,6 @@ class Rocco
defaults = {
:language => 'ruby',
:comment_chars => '#',
:webservice => false
}
@options = defaults.merge(options)
@sources = sources
@ -162,9 +161,10 @@ class Rocco
code_stream = code_blocks.join("\n\n# DIVIDER\n\n")
code_html =
if @options[:webservice]
if `which pygmentize` == ""
puts "Warning: pygmentize not installed. Using pygmentize.appspot.com"
highlight_webservice(code_stream)
else
elsif
highlight_pygmentize(code_stream)
end
@ -200,6 +200,8 @@ class Rocco
code_html
end
# Pygments is not one of those things that's trivial for a ruby user to install,
# so we'll fall back on a webservice to highlight the code if it isn't available.
def highlight_webservice(code)
Net::HTTP.post_form(
URI.parse('http://pygments.appspot.com/'),