I'm doing a lot of java work and I would like to use php's syntax highlighting since It worked so great with php. I've been able to do it ok but php requires me to do the <? at the beginning of every java file and I don't want to have to do this to every java file (lots) Anyone know how I could do this in java?
Below is the code sample I have been using for years with php
function highlight($filename) {
if ((substr($filename, -5) == '.java')) {
ob_start();
show_source($filename);
$buffer = ob_get_contents();
ob_end_clean();
} else {
$argv = '-q -p - -E --language=html --color '.escapeshellcmd($filename);
$buffer = array();
exec("enscript $argv", $buffer);
$buffer = join("\n", $buffer);
$buffer = eregi_replace('<?', "", $buffer);
$buffer = eregi_replace('^.*<PRE>', '<pre>', $buffer);
$buffer = eregi_replace('</PRE>.*$', '</pre>', $buffer);
}
// Making it XHTML compatible.
$buffer = str_replace("<?","",$buffer);
$buffer = eregi_replace('<FONT COLOR="([^"]*)">',
'<span style="color:\1">', $buffer);
$buffer = eregi_replace('</FONT>', '</style>', $buffer);
return $buffer;
}
?>