Skip to content

Commit

Permalink
Item692: port to foswiki & add perl support
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/DpSyntaxHighlighterPlugin@1839 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AndrewJones authored and AndrewJones committed Jan 7, 2009
1 parent 8a065fc commit ef37f0f
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 62 deletions.
Expand Up @@ -35,6 +35,7 @@ The following languages are supported:
* vb, vb.net
* delphi, pascal
* js, jscript, javascript
* pl, perl
* php
* py, python
* ruby
Expand Down Expand Up @@ -69,17 +70,18 @@ function hello () {

---++ Plugin Info

| Plugin Author(s): | TWiki:Main.AndrewRJones |
| Plugin Author(s): | Foswiki:Main.AndrewJones |
| Plugin Version: | %$VERSION% |
| Dp Syntax Highlighter Version: | 1.5.2 (25 Mar 2008) |
| Copyright: | © 2007 TWiki:Main.AndrewRJones |
| Copyright: | © 2007 - 2009 Foswiki:Main.AndrewJones |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
| Dp Syntax Highlighter License: | [[http://www.gnu.org/licenses/lgpl.html][LGPL (Gnu Lesser General Public License)]] |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 07 Jan 2009 | Ported to Foswiki; Will now use jQuery if found; Added support for Perl. Thanks to [[http://code.google.com/p/syntaxhighlighter/issues/detail?id=113&sort=-modified&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary%20Modified][Marty Kube]]. |
| 25 Mar 2008 | 1.5.2 -- Arthur Clemens: Added support for !ActionScript 3. Thanks to [[http://www.digitalflipbook.com/archives/2007/09/as3_syntax_high.php][Mark Walters]] (digitalflipbook.com). |
| 14646 | Bugs:Item4460: Fixed adding JS into highlighted HTML (#3) |
| 14642 | Bugs:Item4516: Upgrade highlighter to 1.5.1 |
| 14046 | Bugs:Item4215: Initial version |
| 14646 | Fixed adding JS into highlighted HTML (#3) |
| 14642 | Upgrade highlighter to 1.5.1 |
| 14046 | Initial version |
| TWiki Dependency: | $TWiki::Plugins::VERSION 1.1 |
| Dp Syntax Highlighter Home | http://code.google.com/p/syntaxhighlighter |
| Plugin Home: | http://twiki.org/cgi-bin/view/Plugins/DpSyntaxHighlighterPlugin |
Expand Down
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2007 Andrew Jones, andrewjones86@googlemail.com
# Copyright (C) 2007 - 2009 Andrew Jones, andrewjones86@googlemail.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -14,7 +14,7 @@
#
# For licensing info read LICENSE file in the TWiki root.

package TWiki::Plugins::DpSyntaxHighlighterPlugin;
package Foswiki::Plugins::DpSyntaxHighlighterPlugin;
use strict;

use vars qw( $VERSION $RELEASE $NO_PREFS_IN_TOPIC $SHORTDESCRIPTION $pluginName $rootDir $doneHead );
Expand All @@ -28,13 +28,13 @@ $SHORTDESCRIPTION = 'Client side syntax highlighting using the [[http://code.goo
sub initPlugin {

# check for Plugins.pm versions
if( $TWiki::Plugins::VERSION < 1.026 ) {
TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
if( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
return 0;
}

$rootDir = TWiki::Func::getPubUrlPath() . '/' . # /pub/
TWiki::Func::getTwikiWebname() . '/' . # TWiki/
$rootDir = Foswiki::Func::getPubUrlPath() . '/' . # /pub/
Foswiki::Func::getTwikiWebname() . '/' . # TWiki/
$pluginName . '/' . # DpSyntaxHighlighterPlugin
'dp.SyntaxHighlighter';

Expand Down Expand Up @@ -86,19 +86,20 @@ sub _handleTag {
# brush
my $brush = '';
for ($lang){
/as3|actionscript3/ and $brush = "AS3", last;
/css/ and $brush = "Css", last;
/c#|c-sharp|csharp/ and $brush = "CSharp", last;
/^c$|cpp|c\+\+/ and $brush = "Cpp", last;
/vb|vb\.net/ and $brush = "Vb", last;
/delphi|pascal/ and $brush = "Delphi", last;
/js|jscript|javascript/ and $brush = "JScript", last;
/^java$/ and $brush = "Java", last;
/php/ and $brush = "Php", last;
/py|python/ and $brush = "Python", last;
/ruby|ror|rails/ and $brush = "Ruby", last;
/sql/ and $brush = "Sql", last;
/xml|xhtml|xslt|html/ and $brush = "Xml", last;
/as3|actionscript3/i and $brush = "AS3", last;
/css/i and $brush = "Css", last;
/c#|c-sharp|csharp/i and $brush = "CSharp", last;
/^c$|cpp|c\+\+/i and $brush = "Cpp", last;
/vb|vb\.net/i and $brush = "Vb", last;
/delphi|pascal/i and $brush = "Delphi", last;
/js|jscript|javascript/i and $brush = "JScript", last;
/^java$/i and $brush = "Java", last;
/php/i and $brush = "Php", last;
/pl|perl/i and $brush = "Perl", last;
/py|python/i and $brush = "Python", last;
/ruby|ror|rails/i and $brush = "Ruby", last;
/sql/i and $brush = "Sql", last;
/xml|xhtml|xslt|html/i and $brush = "Xml", last;
}
$out .= "<script type=\"text/javascript\" src='$rootDir/Scripts/shBrush$brush.js'></script>";

Expand All @@ -114,40 +115,34 @@ sub _doHead {
$doneHead = 1;

# style sheet
TWiki::Func::addToHEAD(
$pluginName . '_STYLE',
"<style type='text/css' media='all'>\@import url($rootDir/Styles/SyntaxHighlighter.css);</style>"
);
my $style = "<style type='text/css' media='all'>\@import url($rootDir/Styles/SyntaxHighlighter.css);</style>";

# core javascript file
TWiki::Func::addToHEAD(
$pluginName . '_CORE',
"<script type=\"text/javascript\" src='$rootDir/Scripts/shCore.js'></script>"
);
my $core = "<script type=\"text/javascript\" src='$rootDir/Scripts/shCore.js'></script>";

my $script = <<"EOT";
<script type="text/javascript">
// use dp.SyntaxHighlighter namespace
dp.SyntaxHighlighter.twikirender = function(){
dp.SyntaxHighlighter.render = function(){
dp.SyntaxHighlighter.ClipboardSwf = '$rootDir/Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
}
if (typeof YAHOO != "undefined") {
if (typeof jQuery != 'undefined') {
// jQuery
\$(document).ready(dp.SyntaxHighlighter.render);
} else if (typeof YAHOO != "undefined") {
// YUI
YAHOO.util.Event.onDOMReady(dp.SyntaxHighlighter.twikirender);
} else if (typeof twiki != "undefined"){
// TWiki 4.2
foswiki.Event.addLoadEvent(dp.SyntaxHighlighter.twikirender);
} else if (typeof addLoadEvent != "undefined") {
// TWiki 4.1
addLoadEvent(dp.SyntaxHighlighter.twikirender);
YAHOO.util.Event.onDOMReady(dp.SyntaxHighlighter.render);
} else if (typeof foswiki != "undefined"){
// foswiki
foswiki.Event.addLoadEvent(dp.SyntaxHighlighter.render);
} else {
alert("Can't add load event for DpSyntaxHighlighterPlugin. Please contact your System Administrator.");
}
</script>
EOT

TWiki::Func::addToHEAD($pluginName . '_RENDER',$script);
Foswiki::Func::addToHEAD( $pluginName, $style . $core . $script );
}

1;
19 changes: 19 additions & 0 deletions lib/Foswiki/Plugins/DpSyntaxHighlighterPlugin/MANIFEST
@@ -0,0 +1,19 @@
# Release manifest for DpSyntaxHighlighterPlugin
data/System/DpSyntaxHighlighterPlugin.txt 0644 Documentation
lib/Foswiki/Plugins/DpSyntaxHighlighterPlugin.pm 0644 Perl module
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/clipboard.swf 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushCSharp.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushCpp.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushCss.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushDelphi.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushJScript.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushJava.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushPerl.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushPhp.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushPython.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushRuby.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushSql.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushVb.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shBrushXml.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Scripts/shCore.js 0644
pub/System/DpSyntaxHighlighterPlugin/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css 0644
Expand Up @@ -2,10 +2,10 @@
BEGIN {
unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} );
}
use TWiki::Contrib::Build;
use Foswiki::Contrib::Build;

# Create the build object
$build = new TWiki::Contrib::Build('DpSyntaxHighlighterPlugin');
$build = new Foswiki::Contrib::Build('DpSyntaxHighlighterPlugin');

# (Optional) Set the details of the repository for uploads.
# This can be any web on any accessible TWiki installation.
Expand Down
18 changes: 0 additions & 18 deletions lib/TWiki/Plugins/DpSyntaxHighlighterPlugin/MANIFEST

This file was deleted.

@@ -0,0 +1,65 @@
/**
* Code Syntax Highlighter.
* Version 1.5.2
* Copyright (C) 2004-2008 Alex Gorbatchev
* http://www.dreamprojections.com/syntaxhighlighter/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Perl brush contributed by Marty Kube */
dp.sh.Brushes.Perl = function()
{
var funcs =
'abs accept alarm atan2 bind binmode chdir chmod chomp chop chown chr ' +
'chroot close closedir connect cos crypt defined delete each endgrent ' +
'endhostent endnetent endprotoent endpwent endservent eof exec exists ' +
'exp fcntl fileno flock fork format formline getc getgrent getgrgid ' +
'getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr ' +
'getnetbyname getnetent getpeername getpgrp getppid getpriority ' +
'getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid ' +
'getservbyname getservbyport getservent getsockname getsockopt glob ' +
'gmtime grep hex index int ioctl join keys kill lc lcfirst length link ' +
'listen localtime lock log lstat map mkdir msgctl msgget msgrcv msgsnd ' +
'oct open opendir ord pack pipe pop pos print printf prototype push ' +
'quotemeta rand read readdir readline readlink readpipe recv rename ' +
'reset reverse rewinddir rindex rmdir scalar seek seekdir select semctl ' +
'semget semop send setgrent sethostent setnetent setpgrp setpriority ' +
'setprotoent setpwent setservent setsockopt shift shmctl shmget shmread ' +
'shmwrite shutdown sin sleep socket socketpair sort splice split sprintf ' +
'sqrt srand stat study substr symlink syscall sysopen sysread sysseek ' +
'system syswrite tell telldir time times tr truncate uc ucfirst umask ' +
'undef unlink unpack unshift utime values vec wait waitpid warn write';

var keywords =
'bless caller continue dbmclose dbmopen die do dump else elsif eval exit ' +
'for foreach goto if import last local my next no our package redo ref ' +
'require return sub tie tied unless untie until use wantarray while';

this.regexList = [
{ regex: new RegExp('#[^!].*$', 'gm'), css: 'comment' }, // comments
{ regex: new RegExp('^\\s*#!.*$', 'gm'), css: 'preprocessor' }, //shebang
{ regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string' },
{ regex: dp.sh.RegexLib.SingleQuotedString, css: 'string' },
{ regex: new RegExp('(\\$|@|%)\\w+', 'g'), css: 'vars' },
{ regex: new RegExp(this.GetKeywords(funcs), 'gmi'), css: 'func' },
{ regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword' }
];

this.CssClass = 'dp-perl';
this.Style =
'.dp-perl .vars { color: #996600; }' +
'.dp-perl .func { color: #006666; }';
}

dp.sh.Brushes.Perl.prototype = new dp.sh.Highlighter();
dp.sh.Brushes.Perl.Aliases = ['perl', 'Perl'];

0 comments on commit ef37f0f

Please sign in to comment.