HTML Tidy with Text Wrangler

Finally getting around to automating HTML Tidy and found a useful blog post that helped.

Move to folder: ~/Library/Application Support/TextWrangler/Text Filters/

Using your favorite text editor create a file called HTML Tidy.sh containing the script:

#!/bin/sh
# run "tidy" on the file given as 1st (and only) parameter.
#
/usr/bin/tidy -utf8 -asxhtml -indent -wrap 100 -quiet 2> /dev/null

You may have to restart TextWrangler, but now under both Text > Apply Text Filters and Window > Pallates > Text Filters the filter will be available to make your HTML look nice.

Apparently the following shell and python scripts can also be added to address XML and JSON files:

XML Tidy.sh
#!/bin/sh
XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 -

JSON Tidy.py
#!/usr/bin/python
import fileinput
import json
print json.dumps( json.loads(''.join([line.strip() for line in fileinput.input()])), sort_keys=True, indent=2)

Leave a Reply

Your email address will not be published. Required fields are marked *