Skip to content

Instantly share code, notes, and snippets.

@maxenglander
Created December 6, 2011 15:44
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 maxenglander/1438633 to your computer and use it in GitHub Desktop.
Save maxenglander/1438633 to your computer and use it in GitHub Desktop.
Tidy XML with Ruby
module TidyHelper
def self.tidy_xml xml_string
IO.popen("tidy -q --input-xml y --output-xml y --indent 'auto' --indent-attributes y --indent-spaces '4' --wrap '90'", "w+") do |pipe|
buffer = String.new
pipe.puts xml_string
pipe.close_write
while line = pipe.gets
buffer << line
end
buffer
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment