Encode string as HTML in Ruby with tags intact -
this question has answer here:
- how encode/decode html entities in ruby? 7 answers
how encode strings html keep tags intact?
eg
<div id='blah'>i brown fox > > </div>
becomes
<div id='blah'>i brown fox > > </div>
why not use xml/html builder nokogiri?
simply install gem.
gem install nokogiri
the following little script created based on provided in question:
require 'nokogiri' builder = nokogiri::html::builder.new |doc| doc.div(:id => 'blah') { doc.text "i brown fox > >" } end puts builder.to_html
gives following html snippit.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/tr/rec-html40/loose.dtd"> <div id="blah">i brown fox > ><id>hello</id> </div>
Comments
Post a Comment