I’m using Ruby (and Nokogiri in case that is helpful) to encode some documents. I want to change actual unicode characters (like “) to html entities (like “). How do I do this? I know I can do a single character with something like
s = '“'
puts "&##{.unpack('U').first};" # gives “
but is there a way to do this properly using iconv or nokogiri?
I’ve come up with this method, which takes a quite brute-force approach which is surely (hopefully?) replaced by a compiled library solution? It works though: