Adding XML and HTML support.

Also splitting Pygmentize's type on `+`, and only using the first bit.
`xml+whatever` => `xml` and so on.  Clever.

Closes issue #36.
This commit is contained in:
Mike West 2011-04-19 20:03:54 +02:00
commit 6736281302

View File

@ -171,7 +171,7 @@ class Rocco
def detect_language def detect_language
@_language ||= @_language ||=
if pygmentize? if pygmentize?
%x[pygmentize -N #{@file}].strip! %x[pygmentize -N #{@file}].strip.split('+').first
else else
"text" "text"
end end
@ -228,6 +228,11 @@ class Rocco
:multi => { :start => "/**", :middle => "*", :end => "*/" }, :multi => { :start => "/**", :middle => "*", :end => "*/" },
:heredoc => nil :heredoc => nil
}, },
"html" => {
:single => nil,
:multi => { :start => '<!--', :middle => nil, :end => '-->' },
:heredoc => nil
},
"java" => C_STYLE_COMMENTS, "java" => C_STYLE_COMMENTS,
"js" => C_STYLE_COMMENTS, "js" => C_STYLE_COMMENTS,
"lua" => { "lua" => {
@ -247,6 +252,11 @@ class Rocco
:heredoc => "<<-" :heredoc => "<<-"
}, },
"scheme" => { :single => ";;", :multi => nil, :heredoc => nil }, "scheme" => { :single => ";;", :multi => nil, :heredoc => nil },
"xml" => {
:single => nil,
:multi => { :start => '<!--', :middle => nil, :end => '-->' },
:heredoc => nil
},
} }
def generate_comment_chars def generate_comment_chars
@ -420,7 +430,7 @@ class Rocco
divider_output = Regexp.new( divider_output = Regexp.new(
[ "\\n*", [ "\\n*",
span, span,
Regexp.escape(front), Regexp.escape(CGI.escapeHTML(front)),
' DIVIDER', ' DIVIDER',
espan, espan,
"\\n*" "\\n*"
@ -432,11 +442,11 @@ class Rocco
divider_input = "\n\n#{front}\nDIVIDER\n#{back}\n\n" divider_input = "\n\n#{front}\nDIVIDER\n#{back}\n\n"
divider_output = Regexp.new( divider_output = Regexp.new(
[ "\\n*", [ "\\n*",
span, Regexp.escape(front), espan, span, Regexp.escape(CGI.escapeHTML(front)), espan,
"\\n", "\\n",
span, "DIVIDER", espan, span, "DIVIDER", espan,
"\\n", "\\n",
span, Regexp.escape(back), espan, span, Regexp.escape(CGI.escapeHTML(back)), espan,
"\\n*" "\\n*"
].join, Regexp::MULTILINE ].join, Regexp::MULTILINE
) )