lib/rouge/cli.rb in rouge-1.11.1 vs lib/rouge/cli.rb in rouge-2.0.0
- old
+ new
@@ -179,10 +179,12 @@
end
def self.parse(argv)
opts = {
:formatter => 'terminal256',
+ :theme => 'thankful_eyes',
+ :css_class => 'codehilite',
:input_file => '-',
:lexer_opts => {},
:formatter_opts => {},
}
@@ -193,16 +195,18 @@
opts[:input_file] = argv.shift
when '--mimetype', '-m'
opts[:mimetype] = argv.shift
when '--lexer', '-l'
opts[:lexer] = argv.shift
- when '--formatter', '-f'
+ when '--formatter-preset', '-f'
opts[:formatter] = argv.shift
+ when '--theme', '-t'
+ opts[:theme] = argv.shift
+ when '--css-class', '-c'
+ opts[:css_class] = argv.shift
when '--lexer-opts', '-L'
opts[:lexer_opts] = parse_cgi(argv.shift)
- when '--formatter-opts', '-F'
- opts[:formatter_opts] = parse_cgi(argv.shift)
when /^--/
error! "unknown option #{arg.inspect}"
else
opts[:input_file] = arg
end
@@ -244,13 +248,20 @@
@mimetype = opts[:mimetype]
end
@lexer_opts = opts[:lexer_opts]
- formatter_class = Formatter.find(opts[:formatter]) \
- or error! "unknown formatter #{opts[:formatter]}"
+ theme = Theme.find(opts[:theme]).new or error! "unknown theme #{opts[:theme]}"
- @formatter = formatter_class.new(opts[:formatter_opts])
+ @formatter = case opts[:formatter]
+ when 'terminal256' then Formatters::Terminal256.new(theme)
+ when 'html' then Formatters::HTML.new
+ when 'html-pygments' then Formatters::HTMLPygments.new(Formatters::HTML.new, opts[:css_class])
+ when 'html-inline' then Formatters::HTMLInline.new(theme)
+ when 'html-table' then Formatters::HTMLTable.new(Formatters::HTML.new)
+ else
+ error! "unknown formatter preset #{opts[:formatter]}"
+ end
end
def run
formatter.format(lexer.lex(input), &method(:print))
end