RedCloth Hard Breaks

Has anybody gotten :hard_breaks to work with RedCloth?

I’m doing:

self.body_html = RedCloth.new(self.body).to_html(:textile)

which works, except that it doesn’t transform hard breaks to

tags, which is really important for me.

However, if I do:

self.body_html = RedCloth.new(self.body, [ :hard_breaks
]).to_html(:textile)

then it converts ALL breaks into
tags, including what should be
paragraph breaks, which get transformed into two consecutive

tags.

Anybody know a workaround for this?

Thanks!
Ryan

I’m not sure I understand the problem. What do you expect it to do with
paragraph breaks?

On 1/27/06, Paul B. [email protected] wrote:

I’m not sure I understand the problem. What do you expect it to do with
paragraph breaks?

Ok, well let me go to Why’s Textile Reference
(Textile Reference).

Under the heading “LINE BREAKS” it says “Line breaks are converted to
HTML breaks.”

So the text:

I spoke.
And none replied.

would be converted to

I spoke. And none replied.

What I want is to insert a
tag instead of an HTML break. So my
desired output would look like this:

I spoke.
And none replied.

Any idea how I can do this?

Thanks!

irb(main):001:0> require ‘RedCloth’
=> true
irb(main):002:0> RedCloth.new(“hello\nworld”,[ :hard_breaks
]).to_html(:textile).to_s
=> “

hello
world

Paul B. wrote:

irb(main):001:0> require ‘RedCloth’
=> true
irb(main):002:0> RedCloth.new(“hello\nworld”,[ :hard_breaks
]).to_html(:textile).to_s
=> “

hello
world

I think the issue is this:

irb(main):002:0> RedCloth.new(“hello\n\n\nworld\nhello\nagain”,
[:hard_breaks]).
to_html(:textile).to_s
=> “

hello
\nworld
hello
again


irb(main):003:0>
RedCloth.new(“hello\n\n\nworld\nhello\nagain”).to_html(:textile
).to_s
=> “

hello

\n\n\n\t

world\nhello\nagain


irb(main):004:0>

IE at the moment this:

hello

world
hello
again

goes to either

hello
world
hello
again

or:

hello

world hello again

What we really would like is this:

hello

world
hello
again

IE 2+ breaks = paragraph, 1 break = br

On 1/27/06, Richard L. [email protected] wrote:

What we really would like is this:

hello

world
hello
again

IE 2+ breaks = paragraph, 1 break = br

Yes! Richard you nailed it.

I’ve been experimenting with using a custom block (as Why described on
http://redhanded.hobix.com/inspect/usingRedcloth3.html), without much
success.

Something like:

text = "My first paragraph
and second line.

My second paragraph
and second line.

My third paragraph."

class CustomRedCloth < RedCloth
def textile_code( tag, atts, cite, content )
content.gsub(/\n/, “
”)
end
end

t1 = CustomRedCloth.new(text).to_html

On Thu, 26 Jan 2006 16:03:32 -0800, Ryan H. wrote:

However, if I do:

self.body_html = RedCloth.new(self.body, [ :hard_breaks ]).to_html(:textile)

then it converts ALL breaks into
tags, including what should be
paragraph breaks, which get transformed into two consecutive

tags.

You’re not using RedCloth 3.0.4, are you? That’s horribly broken, and I
seem to remember running into exactly that bug with it… someone was
refactoring it but I haven’t heard any updates lately, and so the
solution
is to fall back to 3.0.3.

Falling back to RedCloth 3.0.3 worked for me as well. Thanks Jay!

Jay L. wrote:

You’re not using RedCloth 3.0.4, are you? That’s horribly broken, and I
seem to remember running into exactly that bug with it… someone was
refactoring it but I haven’t heard any updates lately, and so the solution
is to fall back to 3.0.3.

I was using 3.0.4 yes and can confirm that falling back to 3.0.3 gets me
what I want.

Thanks for that!

My host, Dreamhost, has both 3.0.3 and 3.0.4 installed. How can I
preferentially load 3.0.3? I tried appending:

require_gem 'RedCloth', '!= 3.0.4'

to the end of my config/environment.rb, and killing Rails:

killall -9 dispatch.fcgi

(Yes, FastCGI was working before this.) But I get this warning:

Application error
Rails application failed to start properly

I’ve also tried this line instead:

require_gem 'RedCloth', '!= 3.0.4'

No avail. Any insights?

-B…