
RedCloth doubles notextile-content (Coderay)
Reported by bourne7 | January 6th, 2011 @ 10:58 AM
RedCloth 4.2.3 und Coderay 0.9.6
I combine Redcloth and Coderay. Below is the coderay helper that wraps additional notextile-tags around its output for Redcloth.
module ApplicationHelper
def coderay(text)
text.gsub!(/\<code(?: lang="(.+?)")?\>(.+?)\<\/code\>/m) do
code = CodeRay.scan($2, $1).div(:css => :class)
"<notextile>#{code}</notextile>"
end
return text.html_safe
end
end
<% @test = coderay('Test of a *simple* line <code lang="ruby"> def hello puts "Hello, world!" end </code> Test of a final _simple_ line') %>
Test of a *simple* line <notextile><div class="CodeRay"> <div class="code"><pre> <span class="r">def</span> <span class="fu">hello</span> puts <span class="s"><span class="dl">"</span><span class="k">Hello, world!</span><span class="dl">"</span></span> <span class="r">end</span> </pre></div> </div> </notextile> Test of a final _simple_ line
This part works as expected.
Now we put this Variable in Redcloth:
<% @final = textilize(@test) %> # omitted the raw before textile for the output
<%= @final %>
<p>Test of a <strong>simple</strong> line <div class="CodeRay"> <div class="code"><pre> <span class="r">def</span> <span class="fu">hello</span> puts <span class="s"><span class="dl">"</span><span class="k">Hello, world!</span><span class="dl">"</span></span> <span class="r">end</span> </pre><div class="CodeRay"><br /> <div class="code"><pre> <span class="r">def</span> <span class="fu">hello</span> puts <span class="s"><span class="dl">"</span><span class="k">Hello, world!</span><span class="dl">"</span></span> <span class="r">end</span> </pre></div></p> </div> <p></notextile> Test of a final <em>simple</em> line</p>
Now, the textile has been created but the part containing the Coderay has been doubled.
Comments and changes to this ticket
-
Markus Proske January 24th, 2011 @ 02:45 PM
I pushed a demo on GitHub: https://github.com/markusproske/redcloth_coderay_demo
Works with 4.1.1, does not work with 4.1.9, 4.2.2, 4.2.3. -
Jason Garber February 1st, 2011 @ 10:19 AM
- State changed from new to open
- Assigned user set to Jason Garber
I've spent about four hours looking into this and I can't figure it out. I have narrowed it down to this chunk of Textile:
This is <notextile><div> <pre>Redcloth *ignore this!*</pre> </div></notextile> in the sentence.
Results in:
<p>This is <div> <pre>Redcloth ignore this!<div><br /> <pre>Redcloth <strong>ignore this!</strong></pre></p> <p></div></notextile> in the sentence.</p>
But I can't figure it out more precisely than that. It's a strange edge case. Let me know if are able to make it do the repetition thing with any simpler input.
-
Jason Garber February 1st, 2011 @ 10:23 AM
Here is the test case I created:
--- name: inline notextile tags containing complex html in: |- This is <notextile><div> <pre>Redcloth *ignore this!*</pre> </div> </notextile> in the sentence. html: |- <p>This is <div> <pre>Redcloth *ignore this!*</pre> </div> in the sentence.</p>
-
Markus Proske February 18th, 2011 @ 10:13 AM
Jason, I did some test with a slightly simplified input and found a "jumping" paragraph and a test case that doubles content. Differences between 4.1.1 and 4.2.7 are in the comments:
# ok 4.1.1, fails in 4.2.7, in 4.2.7 note the "jumping" paragraph: '<p><div><pre>Redcloth</pre></div>Redcloth</p>' test "jg all in one line" do @str = textilize("<notextile><div><pre>Redcloth</pre></div></notextile>Redcloth") @res = '<div><pre>Redcloth</pre></div><p>Redcloth</p>' assert @str == @res end # ok 4.1.1, fails in 4.2.7 and leads to doubled content <p><div><pre>Redcloth<div><pre>Redcloth</pre></p>\n<p></div></notextile>Redcloth</p> test "jg with moving newline test one" do @str = textilize("<notextile><div><pre>Redcloth</pre>\n</div></notextile>Redcloth") @res = "<div><pre>Redcloth</pre>\n</div><p>Redcloth</p>" assert @str == @res end # ok 4.1.1, fails in 4.2.7, again the paragraph jumps: <p><div><pre>Redcloth</pre></div>Redcloth</p> test "jg with moving newline test two" do @str = textilize("<notextile><div><pre>Redcloth</pre></div>\n</notextile>Redcloth").strip @res = '<div><pre>Redcloth</pre></div><p>Redcloth</p>' assert @str == @res end
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.
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