Markus Proske
2011-Jan-23 18:35 UTC
RedCloth 4.1.1 vs. 4.2.3 - weird behaviour with notextile
For a community project I aim to combine RedCloth and Coderay and on doing this, I might have found an issue with RedCloth. I pushed a demo to Github: https://github.com/markusproske/redcloth_coderay_demo The index (http://localhost:3000/) demonstrates the issue. In brief: A page consist of textile. The textile contains @@@ruby somecode @@@ The textile is first feed into Coderay via a helper method and then into RedCloth. To prevent RedCloth from applying markup to the code already rendered by Coderay it is wrapped with <notextile></notextile> which should prevent RedCloth from touching this sections. This works with the fairly old RedCloth 4.1.1 but not with 4.1.9, 4.2.2 and 4.2.3. In these versions, odd effects occur doubling content (and destroying style). I am posting this here as I am quite new to Rails and uncertain, whether this is actually a bug or an error on my side :/ The Helper: def coderay_dressed(text) text.gsub!(/@@@(\w*?)\s+(.+?)\s*@@@/m) do $1 != '''' ? @lang = $1 : @lang = ''none'' code = CodeRay.highlight($2, @lang, :css => :class) "<notextile>#{code}</notextile>" end return text.html_safe end Second, there is another issue which I am sure is my fault. Some problem with safe strings I suppose - maybe you can help me out with this one: 3a.) that works: raw coderay_dressed(''@@@ruby @products = Product.all *Redcloth....'') but if I push the text to @test and call "raw coderay_dressed(@test)" (example 3b in the index) I loose the <notextile> tags. In the show view I directly feed the @article.body "sanitize textilize(coderay_dressed(@article.body))" this works too. Why the difference with using a self-assigned variable and how to fix it? (I tried @test.safe_html with no success). -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jan-23 20:14 UTC
Re: RedCloth 4.1.1 vs. 4.2.3 - weird behaviour with notextile
On Jan 23, 6:35 pm, Markus Proske <markus.pro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: cond, there is another issue which I am sure is my fault. Some problem> with safe strings I suppose - maybe you can help me out with this one: > 3a.) that works: raw coderay_dressed(''@@@ruby @products = Product.all > *Redcloth....'') > but if I push the text to @test and call "raw coderay_dressed(@test)" > (example 3b in the index) I loose the <notextile> tags. > In the show view I directly feed the @article.body "sanitize > textilize(coderay_dressed(@article.body))" this works too. > Why the difference with using a self-assigned variable and how to fix it? > (I tried @test.safe_html with no success).Your various helpers modify their argument in place (you''re calling gsub!), and you call your helpers on @test multiple times, so on the 2nd and later calls, @test probably doesn''t contain what you expected anymore Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Markus Proske
2011-Jan-23 21:03 UTC
Re: RedCloth 4.1.1 vs. 4.2.3 - weird behaviour with notextile
> Your various helpers modify their argument in place (you''re calling > gsub!), and you call your helpers on @test multiple times, so on the > 2nd and later calls, @test probably doesn''t contain what you expected > anymore >This is embarrassing :/ Thanks Fred, the minor issue is solved (and pushed to git). Remains the fact this works with ancient RedCloth but not current versions... Markus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.