diff options
author | murphy <murphy@rubychan.de> | 2008-08-28 06:32:34 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2008-08-28 06:32:34 +0000 |
commit | 28fac2774ecfe248013f02c43ca78b90d0b20b23 (patch) | |
tree | d2ca96ed5aa8d4f3bff58f629a3aea841f3babe1 /lib/coderay | |
parent | 03ffb9431e140e09e5f1a7ae6c2d582c1895554e (diff) | |
download | coderay-28fac2774ecfe248013f02c43ca78b90d0b20b23.tar.gz |
Fixed coderay/for_redcloth escaping.
Diffstat (limited to 'lib/coderay')
-rw-r--r-- | lib/coderay/for_redcloth.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/coderay/for_redcloth.rb b/lib/coderay/for_redcloth.rb index dd8d22f..e2f13d1 100644 --- a/lib/coderay/for_redcloth.rb +++ b/lib/coderay/for_redcloth.rb @@ -18,7 +18,16 @@ module CodeRay # :nodoc: raise 'CodeRay.for_redcloth needs RedCloth 4.0.3 or later.' unless RedCloth::VERSION.to_s >= '4.0.3' RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc RedCloth::Formatters::HTML.module_eval do - undef_method :code, :bc_open, :bc_close + def unescape(html) + replacements = { + '&' => '&', + '"' => '"', + '>' => '>', + '<' => '<', + } + html.gsub(/&(?:amp|quot|[gl]t);/) { |entity| replacements[entity] } + end + undef_method :code, :bc_open, :bc_close, :escape_pre def code(opts) # :nodoc: opts[:block] = true if opts[:lang] && !filter_coderay @@ -26,7 +35,9 @@ module CodeRay # :nodoc: @in_bc ||= nil format = @in_bc ? :div : :span highlighted_code = CodeRay.encode opts[:text], opts[:lang], format, :stream => true - highlighted_code.sub(/\A<(span|div)/) { |m| m + pba(@in_bc || opts) } + highlighted_code.sub!(/\A<(span|div)/) { |m| m + pba(@in_bc || opts) } + highlighted_code = unescape(highlighted_code) unless @in_bc + highlighted_code else "<code#{pba(opts)}>#{opts[:text]}</code>" end @@ -40,6 +51,13 @@ module CodeRay # :nodoc: @in_bc = nil opts[:lang] ? '' : "</pre>\n" end + def escape_pre(text) + if @in_bc ||= nil + text + else + html_esc(text, :html_escape_preformatted) + end + end end end |