Preventing Nokogiri from escaping characters?

浪子不回头ぞ 提交于 2019-11-30 20:15:35

You are obliged to escape some characters in text elements like:

"   "
'   '
<   &lt;
>   &gt;
&   &amp;

If you want your text verbatim use a CDATA section since everything inside a CDATA section is ignored by the parser.

Nokogiri example:

builder = Nokogiri::HTML::Builder.new do |b|
  b.html do
    b.head do
      b.cdata "<%= stylesheet_link_tag 'style'%>"
   end
  end
end
builder.to_html

This should keep you erb tags intact!

Perhaps you want to use the "<<" method to insert raw XML like this:

builder = Nokogiri::XML::Builder.new do |b|
  b.html do
    b.head do
      b << stylesheet_link_tag 'style'
    end
  end
end
builder.to_xml
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!