Forum: Ruby on Rails "textilize" playing silly buggers with me

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.
504771f3dfa86996cdcb48ae14a46df2?d=identicon&s=25 scott (Guest)
on 2005-12-07 02:23
(Received via mailing list)
note: please CC me on replies as I'm not subscribed to the list, thanks.

hey guys,

I'm using <%= textilize(@article.body) %> in my view, but it's doing
funny
things with a html header tag, like so:

-----------------------------
<h2>General Observations<br />

	<ul>
	<li>lots of points here</li>
	</ul></h2>
-----------------------------

however, if I copy and paste the text from the database to a ruby script
and run
that, I get the following:

-----------------------------
require 'redcloth'

r = RedCloth.new "h2. General Observations

* There are almost as many theories on growing cymbidiums as there are
growers."

puts r.to_html
-----------------------------
gives me
-----------------------------
<h2>General Observations</h2>


	<ul>
	<li>There are almost as many theories on growing cymbidiums as there
are
growers.</li>
	</ul>
-----------------------------

you can see that there isn't a <br/> tag and the h2 tag is correct.

Any tips on where I'm going wrong? The database field is a mysql text
field,
utf-8, which I've been editing using phpMyAdmin on localhost.

thanks!
scott
504771f3dfa86996cdcb48ae14a46df2?d=identicon&s=25 scott (Guest)
on 2005-12-07 05:37
(Received via mailing list)
> you can see that there isn't a <br/> tag and the h2 tag is correct.
>
> Any tips on where I'm going wrong? The database field is a mysql text field,
> utf-8, which I've been editing using phpMyAdmin on localhost.

update - looks like there is some kind of bug in redcloth concerning
hard
breaks. if I change the textilize function like so:

--------------------
# Returns the text with all the Textile codes turned into HTML-tags.
        # <i>This method is only available if RedCloth can be
required</i>.
        def textilize(text)
          if text.blank?
            ""
          else
            #textilized = RedCloth.new(text, [ :hard_breaks ])
            #textilized.hard_breaks = true if
textilized.respond_to?("hard_breaks=")
            # *** SM change - hard_breaks screws up large amounts
textilized
text, like a long article, and screws formatting in general
            textilized = RedCloth.new(text)
            textilized.to_html
          end
        end
--------------------

it works just fine with <%= textilize(@article.body) %>

it would appear that changing line breaks to <br/> tags is triggering a
bug in
textilize, because otherwise I can get a long textile-marked-up document
to
render just fine.

thoughts? I guess I'll have to dive into the RedCloth code now, to solve
this.

-sm
2c9df8192dfebf429c5a8b8d9ba0f630?d=identicon&s=25 mike.douglas (Guest)
on 2005-12-07 09:13
(Received via mailing list)
On 12/6/05, scott <scott@evolove.net> wrote:
> thoughts? I guess I'll have to dive into the RedCloth code now, to solve this.

http://fanatico.org/ruby/textile/fix_hard_break.diff - simple fix for
RedCloth.

http://fanatico.org/ruby/textile/allow_redcloth_re... -
patch for Rails. Allows users to pass options to RedCloth through the
textilize method.
251e19913d21aa40a99ec00ed18d202d?d=identicon&s=25 jbaty (Guest)
on 2005-12-07 14:48
(Received via mailing list)
On 12/6/05, scott <scott@evolove.net> wrote:
> > you can see that there isn't a <br/> tag and the h2 tag is correct.
> >
> > Any tips on where I'm going wrong? The database field is a mysql text field,
> > utf-8, which I've been editing using phpMyAdmin on localhost.
>
> update - looks like there is some kind of bug in redcloth concerning hard
> breaks. if I change the textilize function like so:
>

There seem to be a number of little issues with RedCloth 3.0.4
(latest?). Rolling back to 3.0.3 fixed things nicely for me.


--
Jack Baty
Fusionary Media - http://www.fusionary.com
This topic is locked and can not be replied to.