Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding HTML to my RSS/Atom feed in Rails

The default rails XML builder escapes all HTML, so something like:

atom_feed do |feed|  
  @stories.each do |story|  
    feed.entry story do |entry|   
      entry.title story.title
      entry.content "<b>foo</b>"
    end  
  end  
end

will produce the text:

<b>foo</b>

instead of: foo

Is there any way to instruct the XML builder to not escape the XML?

like image 861
Shalmanese Avatar asked Sep 20 '08 00:09

Shalmanese


2 Answers

turns out you need to do

entry.content "<b>foo</b>", :type => "html"

althought wrapping it in a CDATA stops it working.

like image 198
Shalmanese Avatar answered Oct 17 '22 17:10

Shalmanese


entry.content "type" => "html" do
    entry.cdata!(post.content)
end
like image 35
Rodrigo Avatar answered Oct 17 '22 16:10

Rodrigo