简体   繁体   English

在Rails中将HTML添加到我的RSS / Atom提要

[英]Adding HTML to my RSS/Atom feed in Rails

The default rails XML builder escapes all HTML, so something like: 默认的rails XML构建器会转义所有HTML,例如:

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 而不是: foo

Is there any way to instruct the XML builder to not escape the XML? 有没有办法指示XML构建器不转义XML?

turns out you need to do 结果你需要做

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

althought wrapping it in a CDATA stops it working. 虽然将它包装在CDATA中会阻止它工作。

entry.content "type" => "html" do
    entry.cdata!(post.content)
end

http://builder.rubyforge.org/classes/Builder/XmlMarkup.html http://builder.rubyforge.org/classes/Builder/XmlMarkup.html

The special XML characters <, >, and & are converted to <, > and & automatically. 特殊的XML字符<,>和&将自动转换为<,>和&。 Use the << operation to insert text without modification. 使用<<操作插入文本而不进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM