RedCloth

Is this the prefered method to implement RedCloth in your views. I’m
trying to display user input that will sometimes have code references in
it. This strips out all tags. I would like for the tags to be
displayed but not read as html.
Thanks in advance!

<%= RedCloth.new(strip_tags(comment.comment),[:filter_html]).to_html %>

charlie bowman
recentrambles.com

Usually it’s better to convert the text when it gets submitted and store
a clean version in a separate field. That way there’s no overhead of
doing a conversion every time the record is viewed.

Checkout how Typo does it. For instance, the table article has a field
“body” that is what the user entered, and another field “body_html” that
is the red or blue cloth translated text. They have a file called
html_engine.rb in the Lib folder. I just stole that file whole sale for
my app and then in your model just do:

before_save :transform_body

def transform_body
self.body_html = HtmlEngine.transform(body, ‘textile’,
[:filter_html])
end

And in your views do <%= @article.body_html %> instead of @article.body

Easy peasy.

On 27 Feb 2006, at 05:37, Chris Johanesen wrote:

Usually it’s better to convert the text when it gets submitted and
store
a clean version in a separate field. That way there’s no overhead of
doing a conversion every time the record is viewed.

That’s a really obvious way of doing it that i’d never considered -
d’oh!

Has anyone done any benchmarking to roughly determine how much
overhead is involved in throwing a chunk of text at RedCloth?

If not, i’ll have to experiment with that when I get home.

…j

Josh S. wrote:

so conversion overhead is almost entirely irrelevant.

If we are simply talking about sanitizing input, I would argue that
pre-sanitizing on input gives you a safer environment. You won’t have
to worry about changes in the display exposing latent XSS hacks stored
in the database.

However, if we are talking about when to mark up, I do follow the meme
ingrained by my sound recording experience: do no harm to your input.
So yes, like a good compressor or EQ, you only apply it on the way out.
You can always change it then, but once you record it you can’t change
it back. Sure text is a bit more malleable, if there isn’t a good
reason (like safety) then leave it alone. BTW, recording does provide
pre-processing on the bass guitar to protect equipment–particularly if
the player uses funk influenced bass lines. But thats about it.

Jamie Wilson wrote:

On 27 Feb 2006, at 05:37, Chris Johanesen wrote:

Usually it’s better to convert the text when it gets submitted and store
a clean version in a separate field. That way there’s no overhead of
doing a conversion every time the record is viewed.

That’s a really obvious way of doing it that i’d never considered - d’oh!

Has anyone done any benchmarking to roughly determine how much
overhead is involved in throwing a chunk of text at RedCloth?

Hang on a sec… That sounds like premature optimization to me. If you
are properly caching pages or even fragments then pre-converting markup
on submission is largely redundant. I’d say leave off the optimization
until you do some performance profiling to see what actually needs to be
optimized. I know Typo does pre-conversion which may work well for that
setup, but I’ve got a simpler site that runs about 99.9% out of cache,
so conversion overhead is almost entirely irrelevant.

By the way, check out the “textilize” helper in the TextHelper library.
That’s how I convert using RedCloth in the view. If you need different
options for RedCloth, I suggest making your own flavor of helper and use
that.

–josh
blog.hasmanythrough.com

However, if we are talking about when to mark up, I do follow the meme
ingrained by my sound recording experience: do no harm to your input.

Yes, I believe that is why typo keeps a copy of the original input in
say “body” and the converted text in “body_html”.

Of course everything depends on implementation. I’ve been sort of using
Typo as my model as I learn rails, it’s nice to know there are other
ways to do things :slight_smile:

It makes sense that if you’re caching almost everything then maybe do
the conversion on the way out.

On Fri, 03 Mar 2006 16:42:24 -0500, Berin L. wrote:

However, if we are talking about when to mark up, I do follow the meme
ingrained by my sound recording experience: do no harm to your input.

Is there a British method of textilizing, where you do all your markup
and
localization before you commit the record to disk? Is RedCloth warmer
and
punchier than BlueCloth?

Jay

Chris Johanesen wrote:

However, if we are talking about when to mark up, I do follow the meme
ingrained by my sound recording experience: do no harm to your input.

Yes, I believe that is why typo keeps a copy of the original input in
say “body” and the converted text in “body_html”.

There’s also a “filters_column” plugin which makes storing a copy of the
converted text pretty simple if you go that route.

http://wiki.rubyonrails.org/rails/pages/Filters+Column+Plugin

Chris Johanesen wrote:

There’s also a “filters_column” plugin which makes storing a copy of the
converted text pretty simple if you go that route.

http://wiki.rubyonrails.org/rails/pages/Filters+Column+Plugin

I’ve seen this too, but the code doesn’t seem to exist anywhere.

The Subversion repository still works for me, which is where I believe I
got it from originally…

http://yayforgecko.com/svn/filters_column/

There’s also a “filters_column” plugin which makes storing a copy of the
converted text pretty simple if you go that route.

http://wiki.rubyonrails.org/rails/pages/Filters+Column+Plugin

I’ve seen this too, but the code doesn’t seem to exist anywhere.