Encode string as HTML in Ruby with tags intact -


this question has answer here:

how encode strings html keep tags intact?

eg

<div id='blah'>i brown fox > > </div> 

becomes

<div id='blah'>i brown fox &gt; &gt; </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 &gt; &gt;<id>hello</id> </div> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -