Fellows of the cloth -- I''m writing code that subclasses RedCloth and emits styled text that is not HTML. For example, I''m going to be emitting RTF and other formats from Textile or Markdown. I''ve got it working quite well with plainclothed RedCloth, but I can''t seem to override any of the methods in SuperRedCloth. Here''s a sample: http://pastie.textmate.org/59859 I should see a string of C''s for the copyright symbol, but I still see the HTML escape. Will I need to get into the guts of the Ragel scanner to make it do what I want, or am I missing something that can be done in Ruby? Thanks, Geoffrey Grosenbach boss at topfunky.com ........................ Blog | http://nubyonrails.com Podcast | http://podcast.rubyonrails.com Screencast | http://peepcode.com
At 9:38 AM -0700 5/8/07, Geoffrey Grosenbach wrote:>Fellows of the cloth -- > >I''m writing code that subclasses RedCloth and emits styled text that >is not HTML. For example, I''m going to be emitting RTF and other >formats from Textile or Markdown. > >I''ve got it working quite well with plainclothed RedCloth, but I can''t >seem to override any of the methods in SuperRedCloth. Here''s a sample: > >http://pastie.textmate.org/59859 > >I should see a string of C''s for the copyright symbol, but I still see >the HTML escape. > >Will I need to get into the guts of the Ragel scanner to make it do >what I want, or am I missing something that can be done in Ruby?You don''t need to change the Ragel scanner but copyright is a class method. from superredcloth.rb: class << SuperRedCloth def copyright opts "©" end end So this works in irb: require ''superredcloth'' class SuperRedCloth def self.copyright(opts); "CCCC"; end end SuperRedCloth.new("This is my text (c), I copyrighted it!").to_html => "<p>This is my textCCCC, I copyrighted it!</p>" The ragel scanner is calling the SuperRedCloth class methods. I''m not sure what would be the cleanest way to override class methods. -- - Stephen Bannasch Concord Consortium, http://www.concord.org
On 5/8/07, Stephen Bannasch <stephen.bannasch at gmail.com> wrote:> You don''t need to change the Ragel scanner but copyright is a class method.Ahh...that makes sense now. In RedCloth most were written as instance methods. I guess the best approach would be to just re-declare the SuperRedCloth class and override all the methods I need. It feels a bit hackish, but works. Thanks, Geoffrey Grosenbach boss at topfunky.com ........................ Blog | http://nubyonrails.com Podcast | http://podcast.rubyonrails.com Screencast | http://peepcode.com