RedCloth escaping HTML output

708 Views Asked by At

After watching this RailsCast, I thought I'd give RedCloth a try. Unfortunately, it looks like I'm having an issue that involves the resultant HTML being encodeded instead of rendered as straight HTML.

  1. First I added the following to my Gemfile:

    gem 'RedCloth', '4.2.7'
    
  2. I added a basic RedCloth implementation to my view:

    <%= RedCloth.new("* one\n* two\n * three").to_html %>
    
  3. When I "view source" for the page that is rendered, this is what appears:

    &lt;ul&gt;
        &lt;li&gt;one&lt;/li&gt;
        &lt;li&gt;two&lt;/li&gt;
        &lt;li&gt;three&lt;/li&gt;
    &lt;/ul&gt;
    

    The output I expected was the following:

    <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ul>
    

    Am I doing something wrong? Do I need to pass a parameter to to_html or the RedCloth constructor?

1

There are 1 best solutions below

1
On BEST ANSWER

Try this:

<%= raw RedCloth.new("* one\n* two\n * three").to_html %>

Also check out this blog post on the subject.