Defect #43

problem with textilize and :hard_breaks - with solutions

Added by Pavol Murin over 12 years ago. Updated over 12 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution: Affected version:

Description

As described here: http://wiki.rubyonrails.org/rails/pages/RedCloth , there is a problem with :hard_breaks in textilize.
To see the problem in action (taken from the link above):

textilize("h1. This is a test of textile\n\nParagraph\n\nAnother paragraph\n\n* Bullets")

produces:

<h1>This is a test of textile<br />
Paragraph<br />
Another paragraph<br />
<ul>
<li>Bullets</li>
</ul></h1>

(note - this is all a header!!!)

There are several "fixes" proposed - the simplest ones are:

1. don't use :hard_breaks
2. add the following lines add the beginning of app\helpers\application_helper.rb

class RedCloth # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet. # <a href="http://code.whytheluckystiff.net/redcloth/changeset/128">http://code.whytheluckystiff.net/r
edcloth/changeset/128</a>
def hard_break( text )
text.gsub!( /(.)\n(?!\n|\Z| ([#=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
end
end

note - there are people complaining, that 2. doesn't help. It did help me, though :-)

Personally, I find 2 better.

muro

History

#1 Updated by Jean-Philippe Lang over 12 years ago

Thanks. Fix committed.
I personally find 2 usefull :-)

Also available in: Atom PDF