#!/bin/sh
#
# tidy-us
for f in *.html *.htm
do
case "$f" in
'*.html'|'*.htm')
continue
;;
esac
# only process real files
if [ -d "$f" -o -h "$f" ]
then
continue
fi
# also skip MS Word HTML
if grep -i 'generator.*Microsoft Word' "$f" >/dev/null
then
continue
fi
#tidy --word-2000 true $f > $f.tidy 2> $f.err
tidy $f > $f.tidy 2> $f.err
if cmp $f $f.tidy >/dev/null
then
# keep the original, with its file attributes and possibly hardlinks
rm $f.tidy
echo "$f: no changes from tidy"
else
mv -f $f $f.untidy &&
mv -f $f.tidy $f &&
echo "$f: tidied" ||
echo "$f: untidy, replacing with tidied version failed"
fi
if fgrep 'No warnings or errors were found.' $f.err >/dev/null
then
echo "$f: no errors or warnings from tidy"
rm $f.err
else
< $f.err perl -ne 's/line (\d+) column (\d+) - Warning:/$1.$2 / and printf "%s:%s", '"'$f'"', $_'
fi
done