DpSyntaxHighlighterPlugin
Client side syntax highlighting using the
SyntaxHighlighter
This plugin provides client side syntax highlighting using the
SyntaxHighlighter by Alex Gorbatchev.
JavaScript needs to be enabled on the clients web browser for this to work.
Syntax Rules
The code goes between the tags
%CODE{...}%
and
%ENDCODE%
.
%CODE{...}%
can have the following parameters:
Parameter |
Description |
"..." or lang="..." |
the programming language to be highlighted. see Supported Languages. |
autolink="on" |
prevent links in the highlighted code being clickable |
collapse="on" |
force code view to be collapsed |
firstline="value" |
begin line count at value; default value is 1 |
gutter="on" |
enable or disable gutter |
highlight="1,2,3" |
highlight specific lines of code |
smarttabs="on" |
enable or disable smart tabs; note this will only work if there are tabs in your code. |
tabsize="value" |
wet the tab size for tab expansion; default value is 4; note this will only work if there are tabs in your code |
padlinenumbers="value" |
pads line numbers. possible values are - false - don't pad line numbers.
- true - automaticaly pad numbers with minimum required number of leading zeroes.
- [int] - length up to which pad line numbers.
|
toolbar="on" |
enable or disable the toolbar |
quickcode="on" |
enable code copy and paste from double click |
light="on" |
light mode: equavalent to turning off gutter and toolbar |
htmlscript="on" |
allows you to highlight a mixture of HTML/XML code and a script |
Currently all the Foswiki syntax highlighting plugins use the same
%CODE%
syntax. This allows you to switch the highlighter you use without having to update all your topics to the new syntax.
However, it also means that if you have two or more highlighting plugins installed on your system, the plugin that is first in
$Foswiki::cfg{PluginsOrder}
(or by default, first alphabetically)
will consume all the
%CODE%
blocks.
Version 1.2 of this plugin added support for using the
%CODE_DP%
syntax, which allows you to explicitly which plugin you want to highlight your code.
Clearly this is not the best solution to the problem of using more than one highlighting plugin. You can read the background on why this approach was taken in the
task report.
Supported Languages
The following languages are supported:
Brush |
Aliases |
ActionScript3 |
as3, actionScript3 |
AppleScript |
applescript, as |
Bash/shell |
bash, shell, sh |
C# |
c#, c-sharp, csharp |
C++ |
cpp, cc, c++, c, h, hpp, h++ |
ColdFusion |
cf, coldfusion |
CSS |
css |
Delphi |
delphi, pas, pascal |
Diff |
diff, patch |
Erlang |
erl, erlang |
Groovy |
groovy |
Haxe |
haxe, hx |
JavaFX |
javafx, jfx |
Java |
java |
JavaScript |
jscript, js, javascript, json |
Perl |
perl, pl |
PHP |
php |
Plain Text |
plain, text, txt, ascii |
PowerShell |
powershell, ps, posh |
Python |
python, py |
Ruby |
ruby, rails, ror, rb |
Sass |
sass, sccs |
Scala |
scala |
SQL |
sql |
TAP |
tap |
TypeScript |
ts, typescript |
Visual Basic |
vb, vbnet, visualbasic |
XML |
xml, xhtml, xslt, html, plist |
Any of these can be used in the
lang
parameter.
Theming
There are a couple of themes to colorize the highlighted code differently. Use
* Set DPSYNTAXHIGHLIGHTERPLUGIN_THEME = <theme>
to chose from one of the provided themes:
- default
- django
- eclipse
- emacs
- fadetogray
- mdultra
- midnight
- rdark
Examples
Below is a screen shot of how the rendered code will look.
Installation Instructions
You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.
Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".
If you have any problems, or if the extension isn't available in
configure
, then you can still install manually from the command-line. See
http://foswiki.org/Support/ManuallyInstallingExtensions for more help.
If the plugin is installed correcty, the following should be rendered:
%CODE{"php" highlight="2,5" autolink="off"}%
/***********************************
** Multiline block comments
**********************************/
$stringWithUrl = "http://alexgorbatchev.com";
$stringWithUrl = 'hello world';
ob_start("parseOutputBuffer"); // Start Code Buffering
session_start();
function parseOutputBuffer($buf) {
global $portal_small_code, $portal_gzcompress;
global $PHP_SELF, $HTTP_ACCEPT_ENCODING;
// cleaning out the code.
if($portal_small_code && !$portal_gzcompress) {
$buf = str_replace(" ", "", $buf);
$buf = str_replace("\n", "", $buf);
$buf = str_replace(chr(13), "", $buf);
}
}
%ENDCODE%
Info