Created
December 6, 2011 15:44
-
-
Save maxenglander/1438633 to your computer and use it in GitHub Desktop.
Tidy XML with Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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