#!/usr/bin/perl
require "kisrael.pl";

&chugCGI(*input);

$raw = $input{"text"};
$ws=$input{"ws"};



if($raw eq ""){

print "Content-type:text/html\n\n";

print<<__EOQ__;
<head><title>htmlescape</title></head>
<a href="/">kisrael.com</a> | <a href="/tools/">tools</a> |
<b>htmlescape</b><br>
Convert <br>
&amp; to &amp;amp;<br>
&lt; to &amp;lt;<br>
&gt; to &amp;gt;<br>
&quot; to &amp;quot;<br>
<form method="post">

<input type="checkbox" name="ws">Attempt to replicate whitespace in HTML
<br>

<b>original text:</b><br>
<textarea name="text" cols=80 rows=15></textarea><br>

<input type="submit" value="htmlescape"><br>	


</form>
__EOQ__
} else {

    $buffer = $raw;


    $buffer =~ s/\&/'&amp;'/eg;
    $buffer =~ s/\"/'&quot;'/eg;
    $buffer =~ s/\</'&lt;'/eg;
    $buffer =~ s/\>/'&gt;'/eg;



    if(defined($ws)){ #try to convert whitespace \n to b "  " to nbsp, tab, etc
	$buffer =~ s/\r//g;
	$buffer =~ s/\n/"<br>\n"/eg;
	$buffer =~ s/  /"&nbsp;&nbsp;"/eg;
	$buffer =~ s/\t/"&nbsp;&nbsp;&nbsp;&nbsp;"/eg;
    }

 




print "Content-type:text/plain\n\n";
print $buffer;

}
