Forum: Ruby on Rails redcloth poblems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F719c6cb34bd5b691c12b373b7244b4d?d=identicon&s=25 Dorian Mcfarland (tachekent)
on 2006-04-25 18:39
(Received via mailing list)
Hi, I'm having some problems with redcloth(3.0.4 gem) and textilize.

I have a string:
"h2. hello

_what's up?_"

which is being textilized as:

<h2>hello<br />
<em>what&#8217;s up?</em></h2>

so no paragraph and h2 wrapped all the way.

the input is coming from firefox 1.5.2 on a mac

Anybody got any idea what the problem might be?

--
I do things for love or money
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-04-25 19:14
dorian mcfarland wrote:
> Hi, I'm having some problems with redcloth(3.0.4 gem) and textilize.
>
> I have a string:
> "h2. hello
>
> _what's up?_"
>
> which is being textilized as:
>
> <h2>hello<br />
> <em>what&#8217;s up?</em></h2>
>
> so no paragraph and h2 wrapped all the way.
>
> the input is coming from firefox 1.5.2 on a mac
>
> Anybody got any idea what the problem might be?
>
> --
> I do things for love or money

I have had similar issues.  It seems to come down to the :hard_breaks
option, which is enabled by default.  I had to add a hlper method called
textilize to application_helper.rb that overrides the default behavior.

  def textilize(text, options = nil)
    if text.blank?
      ""
    else
      textilized = (options ? RedCloth.new(text, options) :
RedCloth.new(text))
      textilized.to_html
    end
  end

That should make textilize work as expected, and allows you to pass in
your option to the RedCloth object.

However single line breaks will not produce a <br />.  If anyone knows
how to make textile work so "\n" is a <br /> and "\n\n" does paragraphs
I would be quite interested to know.
F719c6cb34bd5b691c12b373b7244b4d?d=identicon&s=25 Dorian Mcfarland (tachekent)
on 2006-04-25 19:47
(Received via mailing list)
yeah, that worked.
I knew there were problems with hard_breaks and rails in 3.0.3. but that
all of this might have been resolved in 3.0.4
I thought that both should be possible. Maybe it's an either/or thing.
It does seem to be a redcloth issue though because textile *should*
handle both at the same time. Try doing it here:

http://textism.com/tools/textile/index.php

Oh well, it's working ok for now but not ideal.

thanks
65c04c5dc6aa662abdd70275b024dbcc?d=identicon&s=25 Raymond Brigleb (Guest)
on 2006-05-19 21:17
(Received via mailing list)
> However single line breaks will not produce a <br />.  If anyone knows
> how to make textile work so "\n" is a <br /> and "\n\n" does paragraphs
> I would be quite interested to know.

I, too, would love to know how to do this with textile/redcloth.

Any suggestions with regards to this would be much appreciated!!

-raymond
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-05-19 22:16
(Received via mailing list)
It seems like this was answered, but in case it wasn't here's a console
dump:

>> s="this is\na two line string"
=> "this is\na two line string"
>> RedCloth.new(s).to_html
=> "<p>this is\na two line string</p>"
>> class RedCloth
>> def hard_breaks; true; end
>> end
=> nil
>> RedCloth.new(s).to_html
=> "<p>this is<br />a two line string</p>"

It does come down to hard line breaks. For further reference, see:

http://redhanded.hobix.com/inspect/usingRedcloth3.html


--
View this message in context:
http://www.nabble.com/redcloth+poblems-t1506534.ht...
Sent from the RubyOnRails Users forum at Nabble.com.
This topic is locked and can not be replied to.