Permalink
Browse files

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.
  • Loading branch information...
2 parents 6193734 + b0582c9 commit 6736281302a267b5c0518ed9259d7b96f6844355 @mikewest mikewest committed Apr 19, 2011
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/rocco.rb
View
@@ -171,7 +171,7 @@ def pygmentize?
def detect_language
@_language ||=
if pygmentize?
- %x[pygmentize -N #{@file}].strip!
+ %x[pygmentize -N #{@file}].strip.split('+').first
else
"text"
end
@@ -228,6 +228,11 @@ def detect_language
:multi => { :start => "/**", :middle => "*", :end => "*/" },
:heredoc => nil
},
+ "html" => {
+ :single => nil,
+ :multi => { :start => '<!--', :middle => nil, :end => '-->' },
+ :heredoc => nil
+ },
"java" => C_STYLE_COMMENTS,
"js" => C_STYLE_COMMENTS,
"lua" => {
@@ -247,6 +252,11 @@ def detect_language
:heredoc => "<<-"
},
"scheme" => { :single => ";;", :multi => nil, :heredoc => nil },
+ "xml" => {
+ :single => nil,
+ :multi => { :start => '<!--', :middle => nil, :end => '-->' },
+ :heredoc => nil
+ },
}
def generate_comment_chars
@@ -420,7 +430,7 @@ def highlight(blocks)
divider_output = Regexp.new(
[ "\\n*",
span,
- Regexp.escape(front),
+ Regexp.escape(CGI.escapeHTML(front)),
' DIVIDER',
espan,
"\\n*"
@@ -432,11 +442,11 @@ def highlight(blocks)
divider_input = "\n\n#{front}\nDIVIDER\n#{back}\n\n"
divider_output = Regexp.new(
[ "\\n*",
- span, Regexp.escape(front), espan,
+ span, Regexp.escape(CGI.escapeHTML(front)), espan,
"\\n",
span, "DIVIDER", espan,
"\\n",
- span, Regexp.escape(back), espan,
+ span, Regexp.escape(CGI.escapeHTML(back)), espan,
"\\n*"
].join, Regexp::MULTILINE
)

0 comments on commit 6736281

Please sign in to comment.