*** SyntaxHighlightingPlugin.pm.orig 2003-01-22 02:40:02.000000000 -0800 --- SyntaxHighlightingPlugin.pm 2005-02-14 15:47:36.000000000 -0800 *************** *** 24,37 **** # # It uses enscript as syntax highlighter. # ! # Use it in your twiki text by writing %begin language% ... %end% # with language = ada asm awk bash c changelog c++ csh delphi diff diffs diffu elisp fortran fortran_pp haskell html idl inf java javascript # ksh m4 mail makefile maple matlab modula_2 nested nroff objc outline pascal perl postscript python rfc scheme sh skill sql states synopsys ! # tcl tcsh tex vba verilog vhdl vrml wmlscript zsh package TWiki::Plugins::SyntaxHighlightingPlugin; ! use IPC::Open2; use vars qw( $web $topic $user $installWeb $VERSION $debug --- 24,37 ---- # # It uses enscript as syntax highlighter. # ! # Use it in your twiki text by writing %SYNTAX{"language"}% ... %ENDSYNTAX% # with language = ada asm awk bash c changelog c++ csh delphi diff diffs diffu elisp fortran fortran_pp haskell html idl inf java javascript # ksh m4 mail makefile maple matlab modula_2 nested nroff objc outline pascal perl postscript python rfc scheme sh skill sql states synopsys ! # tcl tcsh tex vba verilog vhdl vrml wmlscript xml zsh package TWiki::Plugins::SyntaxHighlightingPlugin; ! use IPC::Run qw(run); use vars qw( $web $topic $user $installWeb $VERSION $debug *************** *** 39,62 **** $VERSION = '1.000'; - sub pipeThru - { - my $out; - - $pid = open2( \*Reader, \*Writer, $_[0]); - - print Writer $_[1]; - close(Writer); - - while () - { - $out .= $_; - } - close (Reader); - - return $out; - } - sub highlight { my %langs = ( --- 39,44 ---- *************** *** 113,135 **** "vhdl" => "vhdl", "vrml" => "vrml", "wmlscript" => "wmlscript", "zsh" => "zsh" ); return " Syntax Highlighting: error: $_[0]: undefined language " unless exists $langs{lc($_[0])}; my ($lang, $text, $nb_option, $nb_start) = @_; ! my $highlighted = pipeThru("enscript --color --language=html --highlight=$langs{lc($lang)} -o - -q", $text); if ($highlighted =~ s/.*\\n(.*?)\n?\<\/PRE\>.*/$1/os) { ! if ($nb_option eq " numbered") { my $line = ($nb_start eq "") ? 1 : $nb_start; $highlighted =~ s/(^.*)/sprintf("%5d<\/font><\/b>\t%s", $line++, $1)/mgeo } ! return "
".$highlighted."
<\/td><\/tr><\/table>"; } else { --- 95,148 ---- "vhdl" => "vhdl", "vrml" => "vrml", "wmlscript" => "wmlscript", + "xml" => "html", "zsh" => "zsh" ); return " Syntax Highlighting: error: $_[0]: undefined language " unless exists $langs{lc($_[0])}; my ($lang, $text, $nb_option, $nb_start) = @_; + $lang = '' if ! defined $lang; + $text = '' if ! defined $text; + $nb_option = '' if ! defined $nb_option; + $nb_start = '' if ! defined $nb_start; ! # Get plugin debug flag ! my $enscriptPath = &TWiki::Func::getPreferencesValue( "SYNTAXHIGHLIGHTINGPLUGIN_ENSCRIPT_PATH" ) || "enscript"; ! my $enscriptVersion = &TWiki::Func::getPreferencesValue( "SYNTAXHIGHLIGHTINGPLUGIN_ENSCRIPT_VERSION" ) || 1.63; ! ! my $flag = ($enscriptVersion >= 1.63) ? "--highlight" : "--pretty-print"; ! my @cmd = ($enscriptPath, qw(--color --language=html --output - --silent), "$flag=$langs{lc($lang)}"); + my $highlighted = ''; + eval { + run \@cmd, \$text, \$highlighted; + }; + + if ($@) { + return " Syntax Highlighting: internal error: " . $@ . ""; + } + if ($highlighted =~ s/.*\\n(.*?)\n?\<\/PRE\>.*/$1/os) { ! if ($nb_option =~ /numbered/i) { my $line = ($nb_start eq "") ? 1 : $nb_start; $highlighted =~ s/(^.*)/sprintf("%5d<\/font><\/b>\t%s", $line++, $1)/mgeo } ! ! my $container = &TWiki::Func::getPreferencesValue( "SYNTAXHIGHLIGHTINGPLUGIN_CONTAINER" ) || ''; ! if ($container) ! { ! $container =~ s/<//g; ! $container =~ s/__OUTPUT__/
$highlighted<\/pre>/i;
!            return $container; 
!         }
! 	else 
!         {
!            return "
".$highlighted."
<\/td><\/tr><\/table>"; ! } } else { *************** *** 163,170 **** { &TWiki::Func::writeDebug( "- SyntaxHighlightingPlugin::startRenderingHandler( $_[1] )" ) if $debug; ! # matches %begin [numbered][:n] language% ... %end% ! $_[0] =~ s/^%begin( numbered)?(?:\:(\d+))? ([^%]*?)%\n(.*?)^%end%$/highlight($3, $4, $1, $2)/megos; } # ========================= --- 176,183 ---- { &TWiki::Func::writeDebug( "- SyntaxHighlightingPlugin::startRenderingHandler( $_[1] )" ) if $debug; ! # matches %SYNTAX{"lang" numbered}% ... %ENDSYNTAX% ! $_[0] =~ s/^%SYNTAX\{\s*\"([^"]*)\"\s*\"?(numbered)?\"?\s*(?:\:\s*(\d+))?\s*\}%\s*\n(.*?)^%ENDSYNTAX%\s*$/highlight($1, $4, $2, $3)/megosi; } # =========================