Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created May 6, 2010 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/392292 to your computer and use it in GitHub Desktop.
Save troelskn/392292 to your computer and use it in GitHub Desktop.
def html_to_xml(html)
filename = "/tmp/tidyfy-#{ Time.now.strftime('%Y%m%d%H%M%S') }.html"
File.open(filename, 'w') {|f| f << html }
output = `tidy -asxml -numeric --output-encoding utf8 --doctype omit --add-xml-decl true #{filename} 2> /dev/null`
output.strip.gsub(/<html([^>]*)>/, "<html>")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment