views:

245

answers:

3

I'm looking for recommendations for HTML pretty printers which fulfill the following requirements:

  • Takes HTML as input, and then output a nicely formatted/correctly indented but "graphically equivalent" version of the given input HTML.
  • Must support command-line operation.
  • Must be open-source and run under Linux.
+3  A: 

I think HTML tidy is one of the household names in that field.

Pekka
A: 

How does tidy not fulfill these requirements?

Ignacio Vazquez-Abrams
+5  A: 

Have a look at the HTML Tidy Project: http://tidy.sourceforge.net/

Tidy reads HTML, XHTML and XML files and writes cleaned up markup. For HTML variants, it detects and corrects many common coding errors and strives to produce visually equivalent markup that is both W3C compliant and works on most browsers.

For your needs, here is the command line to call Tidy:

tidy -im inputfile.html
John Riche
Thanks! "tidy -i -m -w 160 -ashtml -utf8 index.html" did the trick! Turns out tidy is installed by default in MacOS X - excellent!
knorv