I have created a text node and inserted into my document like so:
#<Nokogiri::XML::Text:0x3fcce081481c "<%= stylesheet_link_tag 'style'%>">]>
When I try to save the document with this:
File.open('ng.html', 'w+'){|f| f << page.to_html}
I get this in the actual document:
<%= stylesheet_link_tag 'style'%>
Is there a way to disable the escaping and save my page with my erb tags intact?
Thanks!
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
You are obliged to escape some characters in text elements like:
" "
' '
< <
> >
& &
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With