Talk:Syntax Highlight extension
From Wickle Wiki
To get this working, I needed to change SyntaxHighlight.php:46 to use --language instead of -W.
This appears to be the case with enscript 1.6.3, and possibly 1.6.4.
Here's the relevant (old) code:
$cmdline = wfEscapeShellArg( $wgSyntaxSettings->dotCommand) .
" -Eperl --color --Whtml -o".wfEscapeShellArg( $fname.".txt")." " .
wfEscapeShellArg( $fname);
Here's the new version:
$cmdline = wfEscapeShellArg( $wgSyntaxSettings->dotCommand) .
" -Eperl --color --language html -o".wfEscapeShellArg( $fname.".txt")." " .
wfEscapeShellArg( $fname);
I haven't been able to get the language-specific aspects to work, but that's not a big problem :) Thanks for putting this together!
-Rogan
I also made this modification and things are working fine for me, after receiving the following error: Sy ali 02:32, 1 Sep 2005 (CEST)
Warning: file_get_contents(/opt/lampp/htdocs/mw/images/syntax/21183671e1f8fc97dc838821f1546ccc.txt) [function.file-get-contents]: failed to open stream: No such file or directory in /foo/bar/SyntaxHighlight.php
(broken into three lines for easier viewing)
Contents |
thanks for the reminder
I deal with this problem one week ago ... but i forget to update the CVS !!!! ;) thanks a lot, i update now my CVS with another changes too . The mofication you tell efectively is a mofication that works with enscript 1.6.3 and greater. The first implemetation only works with old enscript 1.6.3
--Coffman
Ugly colors
Anyone knows how to enhance the color output from enscript ??? I dont like the colors outputted by the program, they are very ugly. I think it may be color schemas or so, but i cant find it .
re: colors
I'm looking at using GeSHI: http://qbnz.com/highlighter/index.php instead of enscript, it seems to do a better job, but I'd like to see other options.
To Coffman, thanks for hacking this extension :) I would rather have the lanugage tags be stand-alone, but that's the beauty of OSS....
--Rogan
More succinct code tags
I've hacked SyntaxHighlight a bit so the additional<perl/> or <java/> ...tags aren't needed. Instead, just use language tags directly:
<perl> foreach(@myarr){print $_;}</perl> and so on.
Effectively, I defined a function for each language to be supported, then called the old renderSyntax with an additional parameter (the language). This let me discard the conditionals that check for the old internal tags, but it did mean we needed a function for each language. That problem was cleaned up by php's create_function() function, and a loop over an array:
function wfSyntaxExtension() {
global $wgParser;
$langArray = array("java", "perl", "sh", "lisp", "elisp");
foreach ( $langArray as $lang ){
$wgParser->setHook( $lang,
create_function( '$text', 'return renderSyntax( $text, ' . $lang . ');'));
}
}
Ideally, all languages supported by enscript could be dynamically determined, and the array created at runtime. You can play with it in my sandbox here: http://intheworks.biz/wiki/index.php/Sandbox
Let me know if you want the code, or I'll post a link to it when I get it up on my wiki.
--Rogan
Error getting this to work on win32
Hi, im having a lil bit of trouble adding this on a win32 server. i followed the instructions but the code highlight doesnt show up.
--FireDragon 23:20, 18 Apr 2005 (CEST) Tim
Ruby highlighting support
http://jrandomhacker.info/Ruby.st
I have as yet been unable to get this to function as-expected. I don't know enough to summon it up.. doesn't work. <sh/> does work for other code examples, so I know the mechanics are up. Someone please poke me if you know more than me and can help.. Sy ali 03:10, 1 Sep 2005 (CEST)
Patch for (correct) footer filtering and language independency
Hello everybody. I've just installed your extension yesterday and it worked (and looks) very cool, but it had a few quirks that I've fixed and so here's a context diff against the HEAD CVS version from yesterday (r1.3):<nowiki>*** /usr/src/other/wiki/SyntaxHighlight.php.txt 2006-01-17 13:17:35.000000000 +0200
--- /var/www/wiki.linux360.ro/extensions/SyntaxHighlight.php 2006-01-18 00:39:48.000000000 +0200
***************
*** 22,45 ****
{
global $wgUploadDirectory, $wgUploadPath, $IP, $wgSyntaxSettings, $wgArticlePath, $wgTmpDirectory;
$lang="";
! if (ereg ("<perl/>",$timelinesrc))
! {
! $lang = "perl";
! $timelinesrc=str_replace("<perl/>","",$timelinesrc);
! }else if (ereg ("<sh/>",$timelinesrc))
! {
! $lang = "sh";
! $timelinesrc=str_replace("<sh/>","",$timelinesrc);
! }else if (ereg ("<java/>",$timelinesrc))
! {
! $lang = "java";
! $timelinesrc=str_replace("<java/>","",$timelinesrc);
! }else if (ereg ("<cpp/>",$timelinesrc))
! {
! $lang = "cpp";
! $timelinesrc=str_replace("<cpp/>","",$timelinesrc);
! }
!
$hash = md5( $timelinesrc );
$dest = $wgUploadDirectory."/syntax/";
--- 22,31 ----
{
global $wgUploadDirectory, $wgUploadPath, $IP, $wgSyntaxSettings, $wgArticlePath, $wgTmpDirectory;
$lang="";
! if(ereg("<([a-z]+)/>", $timelinesrc, $regs)) {
! $lang = $regs[1];
! $timelinesrc = str_replace("<" . $lang . "/>", "", $timelinesrc);
! };
$hash = md5( $timelinesrc );
$dest = $wgUploadDirectory."/syntax/";
***************
*** 53,81 ****
fwrite($handle, $timelinesrc);
fclose($handle);
- //$cmdline = wfEscapeShellArg( $wgSyntaxSettings->dotCommand) .
- // " -E".$lang." --color --language=html -o".
- //Code for the NEW version of enscript !!!
$cmdline = wfEscapeShellArg( $wgSyntaxSettings->dotCommand) .
! " -E".$lang." --color -w html -o".
! wfEscapeShellArg( $fname.".txt")." " .
! wfEscapeShellArg( $fname);
! // enscript send.pl -Eperl -o aqui.html -Whtml --color
! //echo $cmdline;
! //echo $timelinesrc;
! // exit;
! // break;
! // echo "ADIOS";
$ret = `{$cmdline}`;
unlink($fname);
- /*
- if ( $ret == "" ) {
- // Message not localized, only relevant during install
- return "<div id=\"toc\"><tt>Timeline error: Executable not found. Command line was: {$cmdline}</tt></div>";
- }
- */
}
@$err=file_get_contents( $fname.".err" );
--- 39,52 ----
fwrite($handle, $timelinesrc);
fclose($handle);
$cmdline = wfEscapeShellArg( $wgSyntaxSettings->dotCommand) .
! " -E".$lang." --color -Whtml -o".
! wfEscapeShellArg($fname.".txt")." " .
! wfEscapeShellArg($fname);
$ret = `{$cmdline}`;
unlink($fname);
}
@$err=file_get_contents( $fname.".err" );
***************
*** 83,103 ****
if ( $err != "" ) {
$txt = "<div id=\"toc\"><tt>$err</tt></div>";
} else {
- @$map = file_get_contents( $fname.".map" );
-
- if (substr(php_uname(), 0, 7) == "Windows") {
- $ext = "gif";
- } else {
- $ext = "png";
- }
$txt = file_get_contents( $fname.".txt" );
$txt = eregi_replace("^.*<PRE>\n", '<PRE>', $txt);
! $txt = eregi_replace("\n.*$", '</PRE>', $txt);
! # $txt = "<map name=\"$hash\">{$map}</map>". ! # "<img usemap=\"#{$hash}\" src=\"{$wgUploadPath}/syntax/{$hash}.{$ext}\">";
}
return $txt;
}
-
?>
--- 54,64 ----
if ( $err != "" ) {
$txt = " } else {
$txt = file_get_contents( $fname.".txt" );$txt = eregi_replace("^.*
\n", '<PRE>', $txt);
! $txt = eregi_replace(".*$", '</PRE>', $txt);
}
return $txt;
}
?></nowiki></pre>
Feel free to contact me at radu dot mihailescu at linux360 dot ro for any questions/flames :-)

