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 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)
“#{code}”
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 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).