Extension talk:Enscript
When I install and run this extension on Fedora 6, the Apache error log spits out:
sh: /enscript: No such file or directory
enscript is installed on the machine and is located at the default location:
/usr/bin/enscript
The version of Mediawiki is 1.8.5. Any idea why this is happening?
[edit] take-off on Enscript w/ Kate...
Did something very similar, but using the perl port of Kate. Very clearly ripping off Yedidia, the php looks like:
<?php #---------------------------------------------------------------------------- # Extension initialization #---------------------------------------------------------------------------- $KateVersion = '0.01'; global $wgExtensionCredits; $wgExtensionCredits['parserhook'][] = array( 'name'=>'Kate', 'version'=>$KateVersion, 'author'=>'xxxx', 'url'=>'http://www.mediawiki.org/wiki/Extension:kate', 'description' => 'Show code highlighted w/ Kate' ); $wgExtensionFunctions[] = "wfKate"; function wfKate() { global $wgParser; $wgParser->setHook( "Kate", "renderKate" ); } function renderKate( $input , $argv, &$parser ) { $file['kate'] = "/usr/bin/perl /var/www/html/wiki/extensions/hlhtml.pl"; $file['kate-options'] = $argv['lang']; $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['kate']." ".$file['kate-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("<H1>(stdin)</H1>","",$output); return $output; } ?>
[edit] Enscript issues with MW 1.11.2 and Enscript 1.6.4
Had trouble getting things to work well with MediaWiki 1.11 and Enscript 1.6.4:
- Enscript made a full set of headers and put "credits" after every bit of code
- Odd errors appeared on the rendered page
The following hacked up version works OK but should probably be edited by someone who knows what she/he is doing. It would be really nice to have one footnote per page giving Enscript credit for generating the printout, but that's a bit beyond my skillset at this time...
<?php $EnscriptVersion = '0.2'; #---------------------------------------------------------------------------- # Extension initialization #---------------------------------------------------------------------------- global $wgExtensionCredits; $wgExtensionCredits['parserhook'][] = array ( 'name' => '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 --style=msvc -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); // Added by JR -- Knock off the HTML header, which screws things up pretty badly $ablank = "<! >"; $output = preg_replace ('/<\!DOCTYPE.*>/', $ablank, $output); $output = preg_replace ('/<HTML>\n<HEAD>\n<TITLE>.*TITLE>\n<\/HEAD>/', $ablank, $output); $output = preg_replace ('/<BODY.*>/', $ablank, $output); $output = preg_replace ('/<ADDRESS.*ADDRESS>/', $ablank, $output); $output = preg_replace ('/<A.*>/', $ablank, $output); $output = str_replace ("<H1>(stdin)</H1>", $ablank, $output); $output = str_replace ("<HR>", $ablank, $output); $output = preg_replace ('/<PRE>\n/', "<PRE>", $output); $output = preg_replace ('/<\/BODY>\n<\/HTML>\n/', $ablank, $output); return $output; } ?>
[edit] HTML code cleanings
Replace
$output = str_replace("<H1>(stdin)</H1>","",$output);
with
$output=preg_replace("/^.*<pre>/si","<pre>", $output);
$output=preg_replace("/<\/pre>.*$/si","</pre>", $output);
It will clear all unnecessary HTML tags from output (DOCTYPE, HTML, etc).