#!/usr/bin/sh # # Revision: 1.1 # # History: # # 1.1 - added HTML Tidy integration # - added Perl detection # 1.0 - initial release ### CONFIGURE include="*.htm?" # file types to format backup=no # create backup files? tidy=no # use HTML Tidy? tidycfg=/home/site/tidy/config.txt # HTML Tidy configuration file tidyerr=tidy_errors.txt # HTML Tidy errors file ### PREPARE unset IFS PATH=/usr/bin:/usr/local/bin PERL_BINARY=`whereis perl | cut -f2 -d" "` TIDY_BINARY=~/bin/tidy TIDY_EXISTS=`{ $TIDY_BINARY -v 2> /dev/null; echo $?; }` ### MAIN LOGIC if [ "`dirname $PERL_BINARY`" = "." ]; then echo "Perl not found." 1>&2 exit 1 fi if [ $# -eq 0 ]; then echo "This script is used to format HTML code.\n" echo "Usage: `basename $0` [-r] INPUT [OUTPUT]\n" echo "INPUT can either be a source file or directory. If INPUT is a" echo "file, then an OUTPUT file is required. If INPUT is a directory," echo "the script will format all HTML files in that directory. The -r" echo "switch will make the script parse recursively." exit 1 fi if [ "$1" = "-r" ]; then recurse="$2 -name '$include'" shift fi input=$1 output=$2 formatHTML() { source=$1 if [ "$tidy" = "yes" -a "$TIDY_EXISTS" = 0 ]; then $TIDY_BINARY -config $tidycfg -f $tidyerr $1 > $1.tidy source=$1.tidy fi $PERL_BINARY -e\ ' $html = `cat $ARGV[0]`; $html =~ s/(\r\n?|\n)+/\n/g; # normalize EOLs $html =~ s/\s*