Hi there,
I’m using RedCloth for writing texts, it however doesn’t know anything
about syntax highlighting. So I came up with the idea of combining it
with CodeRay by means of adding a new tag. This is my code so far:
···
======================================================================
require "redcloth"
require "coderay"
module RedCloth::CodeRayHighlighting
def coderay(opts)
CodeRay.scan(opts[:text], :ruby).html(line_numbers: :table, wrap:
:div)
end
end
RedCloth::Formatters::HTML.send(:include, RedCloth::CodeRayHighlighting)
text=<<EOF
Foo bar.
coderay. puts "Hi!"
puts 3
Foo bar.
EOF
puts RedCloth.new(text).to_html
But sadly, it’s doing bad things to the code. Here’s the relevant part
of the generated HTML:
======================================================================
<td class="code"><pre>puts &<span
class="comment">#8216;Hi!&#8217;<br /></span>
puts <span class="integer">3</span></pre></td>
RedCloth obviously converted the quotes into ‘ and ’.
CodeRay interpreted the # as the start of a comment and as a result
the syntax highlighting is completely broken.
How to tell RedCloth that my custom tag wants verbatim text rather
than formatted?
Vale,
Marvin