I am using Nokogiri in Rails to parse my HTML and convert self-closing tags to regular ones. That works great, but it also converts our template tags which are [%
and %]
, so for example:
html = "<a href='[% hello %]'>Hello from [% Us %]</a>"
Nokogiri::HTML::DocumentFragment.parse(html).to_html
will convert to:
<a href='%5B%%20hello%20%%5D'>Hello from [% Us %]</a>
How do I avoid it without using gsub
after the conversion?
This did not help:
html = "<a href='[% hello %]'>Hello from [% Us %]</a>"
doc = Nokogiri::HTML::Document.new
doc.encoding = 'UTF-8'
doc.fragment(html).to_html
#=> "<a href=\"%5B%%20hello%20%%5D\">Hello from [% Us %]</a>"