sub escapeHTML {
my ( $escape, $whitespace ) = @_;
return undef unless defined $escape ;
# make the essential escapes
$escape =~ s/&/&/g;
$escape =~ s/"/"/g;
$escape =~ s/</g;
$escape =~ s/>/>/g;
# these next optional escapes make text look the same when rendered in HTML
if ( $whitespace ) {
$escape =~ s/\t/ /g; # tabs to 4 spaces
$escape =~ s/( {2,})/" " x length $1/eg; # whitespace escapes
$escape =~ s/\n/
\n/g; # newlines to
}
return $escape;
}