#240 new
ronin-98500 (at lighthouseapp)

Creating a custom verbatim tag

Reported by ronin-98500 (at lighthouseapp) | December 6th, 2011 @ 11:04 AM

Hi there,

I always thought that this was only a bugtracker, but I have been told it serves as a general discussion forum as well (see http://www.ruby-forum.com/topic/3143743#1035364 ). So, here comes my problem:

I’m trying to create a custom verbatim tag, i.e. a tag that behaves the same way as the bc element. The reason for this is that I'd like to add Ruby syntax highlighting via CodeRay to my blog posts and and their comments. Here’s the code I’ve tried so far, but it obviously doesn’t do the right thing:

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

The relevant part of the output is this:

<td class="code"><pre>puts &amp;<span
class="comment">#8216;Hi!&amp;#8217;&lt;br /&gt;</span>
puts <span class="integer">3</span></pre></td>

RedCloth converted the quotes into &#8216; and &#8217; which consequently breaks CodeRay’s highlighting and produces what we can see above.

So: Is there any way to tell RedCloth I want my custom tag to receive unformatted text beside monkeypatching RedCloth itself and overwriting the #bc_open, #bc_close and #code methods of the RedCloth::HTML::Formatter class?

Valete,
Marvin

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

RedCloth is a Ruby library for converting Textile into HTML

Shared Ticket Bins

People watching this ticket

Pages