)
- {
- $out .= $_;
- }
- close (Reader);
-
- return $out;
-}
-
sub highlight
{
my %langs = (
@@ -113,23 +95,55 @@
"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 = pipeThru("enscript --color --language=html --highlight=$langs{lc($lang)} -o - -q", $text);
+ my $highlighted = '';
+ eval {
+ run \@cmd, \$text, \$highlighted;
+ };
+
+ if ($@) {
+ return " Syntax Highlighting: internal error: " . $@ . "";
+ }
+
if ($highlighted =~ s/.*\\n(.*?)\n?\<\/PRE\>.*/$1/os)
{
- if ($nb_option eq " numbered")
+ if ($nb_option =~ /numbered/i)
{
my $line = ($nb_start eq "") ? 1 : $nb_start;
$highlighted =~ s/(^.*)/sprintf("%5d<\/font><\/b>\t%s", $line++, $1)/mgeo
}
- return "".$highlighted." <\/td><\/tr><\/table>";
+
+ 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,8 +177,8 @@
{
&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;
+ # 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;
}
# =========================
|
|