htindent indents html code. It is particularly useful when debugging the output of a messy cgi script.

The indenting algorithm is very simple. Every time a newline is printed, it is followed by the indent string printed once for each indent level. Immediatly following newlines are suppressed. A newline is added to the beginning and end of each tag. This effectively puts each tag on its own line. The tags are not altered, so they could span multiple lines if they contain newlines. Opening tags increment the indent level, closing tags decrement it.

Invoked from the command line, htindent reads standard in and writes to standard out. htindent can also be imported as a module from a python program. The function htindent.indent(infile, outfile, q=' ') takes two opened file-like objects. The optional q argument sets the string used to print the 'tabs'.

htindent is free to use and distribute, but carries no warranty.