Extension:Enscript

Description
This Extension is made for syntax highlighting in color your code in various languages - using GNU Enscript.

Download and Installation Instructions
$file['enscript'] = "/usr/bin/enscript"; require_once("extensions/Enscript.php");
 * Make sure enscript is installed on your system.
 * The extension can be downloaded from here : Save as Enscript.php or copied from end of this doc.
 * Save it in your extensions Directory (with write permissions)
 * Edit Enscript.php and set your enscript binary path (line 32) - good chance that the default are OK for you.
 * Add this line to your LocalSettings.php:

Usage

 * 1) !/usr/bin/perl

print "Hello world"; $c = $a + $b;

will look like:

#!/usr/bin/perl  print &quot;Hello world&quot;; $c = $a + $b;

License
This Piece of code is Under Gnu Public License.

The extension itself
'Enscript',    'version'=>$EnscriptVersion,    'author'=>'Yedidia Klein',    'url'=>'http://www.mediawiki.org/wiki/Extension:enscript',    'description' => 'Show code highlighted w/ GNU Enscript'    );

$wgExtensionFunctions[] = "wfEnscript";

function wfEnscript { global $wgParser;

$wgParser->setHook( "Enscript", "renderEnscript" ); }

function renderEnscript( $input, $argv, &$parser ) { $file['enscript'] = "/usr/bin/enscript"; $file['enscript-options'] = " -q --language=html --color -E".$argv['lang']." -o -";

$output="";

$descriptorspec = array(  0 => array("pipe", "r"),  // stdin is a pipe that the child will read from   1 => array("pipe", "w")  // stdout is a pipe that the child will write to ); $cwd = '/tmp'; $ph=proc_open($file['enscript']." ".$file['enscript-options'],$descriptorspec,$pipes,$cwd); fwrite($pipes[0],$input); fclose($pipes[0]);

$output=stream_get_contents($pipes[1]); fclose($pipes[1]);

$return_value = proc_close($ph);

$output = str_replace("(stdin)","",$output); return $output; }

?>