Skip to content

Instantly share code, notes, and snippets.

@cbronazc
Last active December 24, 2015 14:29
Show Gist options
  • Save cbronazc/6813471 to your computer and use it in GitHub Desktop.
Save cbronazc/6813471 to your computer and use it in GitHub Desktop.
Convert xml to html with a ruby script. Basically just a cheap, badly done .html_safe
require 'tempfile'
require 'fileutils'
# To run: ruby ./convert_xml_to_html.rb thefile.xml
#
path = ARGV[0]
begin
orig = File.open(path, 'r')
file = File.open("converted_" + path, "w")
contents = orig.read
contents.gsub!("&lt;", "<")
contents.gsub!("&gt;", ">")
contents.gsub!("&quot;", "\"")
contents.gsub!("&apos;", "\'")
contents.gsub("&amp;", "&")
file.write(contents)
puts path + " converted"
ensure
file.close unless file == nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment