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?
3 个解决方案
#1
10
turns out you need to do
结果你需要做
entry.content "<b>foo</b>", :type => "html"
althought wrapping it in a CDATA stops it working.
虽然将它包装在CDATA中会阻止它工作。
#2
9
entry.content "type" => "html" do
entry.cdata!(post.content)
end
#3
0
http://builder.rubyforge.org/classes/Builder/XmlMarkup.html
The special XML characters <, >, and & are converted to <, > and & automatically. Use the << operation to insert text without modification.
特殊的XML字符<,>和&将自动转换为<,>和&。使用< <操作插入文本而不进行修改。< p>
#1
10
turns out you need to do
结果你需要做
entry.content "<b>foo</b>", :type => "html"
althought wrapping it in a CDATA stops it working.
虽然将它包装在CDATA中会阻止它工作。
#2
9
entry.content "type" => "html" do
entry.cdata!(post.content)
end
#3
0
http://builder.rubyforge.org/classes/Builder/XmlMarkup.html
The special XML characters <, >, and & are converted to <, > and & automatically. Use the << operation to insert text without modification.
特殊的XML字符<,>和&将自动转换为<,>和&。使用< <操作插入文本而不进行修改。< p>