Reformat HTML with Tidy
I had some HTML from a Joomla! site that I wanted to import to this site. The editor I had set up put all the HTML into one huge line, but I wanted to make it nicer to look at so I can maintain it. After a quick look around, I found tidy (official page or old but well written documentation).
It was available in the Ubuntu (Feisty) repositories, so that’s how I installed it. There’s no GUI or anything, it’s all command line. Here are the options I’ve been using with it:
tidy -f err.txt -w 1000 -m test.html
where:
- -f err.txt is where any errors should be written to
- -w means to wrap lines at this many characters (a quick look for an option to turn off line wrap yielded nothing, but this works just as well)
- -m test.html means to reformat the file test.html in place.
So I copy the poorly-formatted code into a file called test.html, run tidy on it, and the same file is then reformatted nicely.