--- dpshplugin/lib/Foswiki/Plugins/DpSyntaxHighlighterPlugin.pm 2009-06-22 11:57:21.517339800 -0700 +++ DpSyntaxHighlighterPlugin.pm.custom 2009-06-22 13:03:32.116927800 -0700 @@ -48,19 +48,23 @@ sub _handleTag { my %params = Foswiki::Func::extractParameters($1); - my $el = $params{el} || 'pre'; + my $el = (lc$params{el} eq 'textarea' ? 'textarea' : 'pre'); my $lang = lc$params{lang} || lc$params{_DEFAULT}; # language my $code = $2; # code to highlight # start - my $out = "<$el name='code' class='$lang"; + my $out = "<$el name='code' class='brush: $lang\;"; # attributes - $out .= ":nogutter" if lc$params{nogutter} eq 'on'; - $out .= ":nocontrols" if lc$params{nocontrols} eq 'on'; - $out .= ":collapse" if lc$params{collapse} eq 'on'; - $out .= ":firstline[$params{firstline}]" if $params{firstline}; - $out .= ":showcolumns" if lc$params{showcolumns} eq 'on'; + $out .= " gutter: false;" if lc$params{nogutter} eq 'on'; + $out .= " toolbar: false;" if lc$params{nocontrols} eq 'on'; + $out .= " collapse: true;" if lc$params{collapse} eq 'on'; + $out .= " first-line: $params{firstline};" if $params{firstline}; + $out .= " wrap-lines: false;" if lc$params{nowrap} eq 'on'; + $out .= " ruler: true;" if lc$params{ ruler} eq 'on'; + $out .= " smart-tabs: false;" if lc$params{nosmarttabs} eq 'on'; + $out .= " tab-size: $params{tabsize};" if $params{tabsize}; + $out .= " highlight: [$params{highlight}];" if $params{highlight}; $out .= "'"; if ($el eq 'textarea') { @@ -82,17 +86,23 @@ for ($lang){ /as3|actionscript3/ and $brush = "AS3", last; /css/ and $brush = "Css", last; + /bash|shell/ and $brush = "Bash", last; /c#|c-sharp|csharp/ and $brush = "CSharp", last; - /^c$|cpp|c\+\+/ and $brush = "Cpp", last; - /vb|vb\.net/ and $brush = "Vb", last; + /^c$|cpp/ and $brush = "Cpp", last; + /vb|vbnet/ and $brush = "Vb", last; /delphi|pascal/ and $brush = "Delphi", last; + /diff|patch/ and $brush = "Diff", last; + /groovy/ and $brush = "Groovy", last; /js|jscript|javascript/ and $brush = "JScript", last; /^java$/ and $brush = "Java", last; + /jfx|javafx/ and $brush = "JavaFX", last; /php/ and $brush = "Php", last; - /^pl$|perl/ and $brush = "Perl", last; - /plain|ascii/ and $brush = "Plain", last; + /^pl$|[Pp]erl/ and $brush = "Perl", last; + /plain|text/ and $brush = "Plain", last; + /ps|powershell/ and $brush = "PowerShell", last; /py|python/ and $brush = "Python", last; /ruby|ror|rails/ and $brush = "Ruby", last; + /scala/ and $brush = "Scala", last; /sql/ and $brush = "Sql", last; /xml|xhtml|xslt|html/ and $brush = "Xml", last; } @@ -101,7 +111,7 @@ return "$pluginName error: The language \"$lang\" is not supported." if $brush eq ''; - $out .= ""; + $out .= ""; _doHead(); @@ -115,27 +125,56 @@ $doneHead = 1; # style sheet - my $style = ""; + my $style = ""; + + # CSS theme to use for output + my $theme = Foswiki::Func::getPreferencesValue("\U$pluginName\_THEME"); + $theme = 'Default' if $theme eq ''; + $style .= ""; + + my $jsDefs = ''; + + # Hide about/print buttons + if (uc(Foswiki::Func::getPreferencesValue("\U$pluginName\_HIDE_ABOUT")) eq 'ON') { + $jsDefs .= "\n delete SyntaxHighlighter.toolbar.items[\"about\"];"; + } + if (uc(Foswiki::Func::getPreferencesValue("\U$pluginName\_HIDE_PRINT")) eq 'ON') { + $jsDefs .= "\n delete SyntaxHighlighter.toolbar.items[\"printSource\"];"; + } + + # SyntaxHighlighter normally tries to guess the width of a space by + # measuring it through javascript. When measuring, it appends the item + # to the document.body, so font-size may not match the Foswiki theme. + # + # This allows an override in WebPreferences. The value is in pixels. + # Set DPSYNTAXHIGHLIGHTERPLUGIN_SPACEWIDTH = 8 + my $spaceWidth = Foswiki::Func::getPreferencesValue("\U$pluginName\_SPACEWIDTH"); + if ($spaceWidth ne '') { + $jsDefs .= "\n SyntaxHighlighter.vars.spaceWidth = $spaceWidth;"; + } # core javascript file - my $core = ""; + my $core = ""; my $script = <<"EOT";