Use RedCloth 2 for sane linebreaking in Textile and how to install on shared hosting 4

Posted by Tim Connor Wed, 28 Mar 2007 16:46:00 GMT

It seems like logical enough behavior – you just want what was entered into the textarea to be represented in the most logical manner in the markup.

This:

A paragraph Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean suscipit metus vitae magna. Phasellus euismod ultrices justo.

Another paragraph Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean suscipit metus vitae magna. Phasellus euismod ultrices justo.

This paragraph
has linebreaks
though
to become this:

<p>A paragraph...</p>
<p>Another paragraph...</p>
<p>This paragraph<br/>
has linebreaks<br/>
though</p>

Unfortunately, this isn’t how it works in RedCloth 3. These are your two options

without :hardbreaks on

<p>A paragraph...</p>
<p>Another paragraph...</p>
<p>This paragraph
has linebreaks
though</p>
with hardbreaks on

<p>A paragraph...<br>
Another paragraph...<br>
This paragraph<br>
has linebreaks<br>
though<br>
</p>

Which means there is no way to get that right spacing (multiple returns where ignored in my testing), much less the markup you want: paragraphs with possibility of linebreaks in them.

The only way I found around this was by installing the latest RedCloth 2. To avoid problems with this being superseded by a later version of RC3 (and to get around not being able to install gems) being installed on the host, you can drop it in vendor and specify a require with a version in environment.rb. If even this won’t work on your shared host, take out the require and just move the redcloth.rb to the root of the vendor folder and Bob’s yer uncle.

Update 04/10/2007

I found this in the Collaboa environment.rb. I haven’t tested it, myself, but it looks like it should work nicely for forcing the version you want.

# We want features from RedCloth trunk (> 3.0.4), so unload the RedCloth gem if any, and re-require
Object.send(:remove_const, :RedCloth) if Object.const_defined?(:RedCloth)
require "#{RAILS_ROOT}/vendor/redcloth/lib/redcloth"