The Syntax Highlighting Plugin is used to emphasize the rendering of your wiki text according to several languages. It currently uses enscript
to render its output.
Recent versions of enscript
support highlighting of the following languages:
ada, asm, awk, bash, c, changelog, cpp, csh, delphi, diff, diffs, diffu, dylan, eiffel, elisp, forth, fortran, fortran_pp, haskell, html, icon, idl, inf, java, javascript, ksh, lua, m4, mail, makefile, matlab, nroff, oberon2, objc, outline, oz, pascal, perl, php, postscript, pyrex, python, rfc, ruby, scheme, sh, skill, smalltalk, sml, sql, states, synopsys, tcl, tcsh, tex, vba, verilog, vhdl, vrml, wmlscript, zsh
You need to installed and enabled the SyntaxHighlightingPlugin to see the actual languages that are available.
Additional languages can be added, see genscript documentation.
To use this plugin, use the following syntax:
<sticky> %CODE{ lang="cpp" num="10" numstep="2" }% ...code... %ENDCODE% </sticky>
The <sticky>
tags are required to prevent TWiki's WYSIWYG editor from removing line breaks inside the code block.
In addition, %SYNTAXHIGHLIGHTING{supported}%
returns the list of currently supported languages as indicated above.
Parameter | Description | Default |
---|---|---|
"..." orlang="..." |
Source language. Supported languages: ada , asm , awk , bash , changelog , cpp , csh , c , delphi , diffs , diff , diffu , dylan , eiffel , elisp , Name: , forth , fortran_pp , fortran , haskell , html , icon , idl , inf , javascript , java , ksh , lua , m4 , mail , makefile , matlab , nroff , oberon2 , objc , outline , oz , pascal , perl , php , postscript , pyrex , python , rfc , ruby , scheme , sh , skill , Smalltalk , sml , sql , states , synopsys , tcl , tcsh , tex , vba , verilog , vhdl , vrml , wmlscript , zsh |
(none, required) |
num="..." |
Show line numbers next to the source code. An integer indicates the start number. Also "on" and "off" |
"off" |
step="..." |
Increment line numbers with the given step. Negative numbers will decrement. | "1" |
style="..." |
Style of box around the source code | light gray box |
numstyle="..." |
Style of line number column | light brown box |
Note: The default can be set in configure
The following text:
<sticky> %CODE{"c++"}% #include <iostream> int main() { // Hello world example std::cout << "Hello, world." << std::endl; } %ENDCODE% </sticky>
gives (if installed):
You can also output numbered lines starting at 10 with this text:
<sticky> %CODE{"sh" num="10"}% #!/bin/sh languages=`enscript --help-highlight | grep 'Name:' | cut -d ' ' -f 2` for l in $languages; do cat << EOF * $l EOF done %ENDCODE% </sticky>
gives (if installed):
Note: You do not need to install anything on the browser to use this extension. The following instructions are for the administrator who installs the extension on the TWiki server.
SyntaxHighlightingPlugin.zip
in your twiki installation directory.
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{EnscriptPath}
# path to enscript script
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{DefaultLang}
# Default language
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{Numbering}
# Default for line numbering, 'off' or 'on'
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{Step}
# Default step of numbering
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{Style}
# Style of pre tag containing the source code
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{NumStyle}
# Style of numbering column
$TWiki::cfg{Plugins}{SyntaxHighlightingPlugin}{Debug}
# Debug setting
%begin sh%
...code...
%end%
tools
directory and into your data
directory. When you run it, it will look through your webs and replace the syntax. Note that its not the best script in the world, so always test it on a copy of your data first!
data/TWiki/SyntaxHighlightingPlugin.txt | Plugin topic |
data/TWiki/VarCODE.txt | Variable documentation topic |
pub/TWiki/SyntaxHighlightingPlugin/cpp-screenshot.png | |
pub/TWiki/SyntaxHighlightingPlugin/cpp-screenshot-300.png | |
lib/TWiki/Plugins/SyntaxHighlightingPlugin.pm | Perl module |
lib/TWiki/Plugins/SyntaxHighlightingPlugin/Config.spec | |
tools/SyntaxHighlightingPlugin_covert.pl |
Plugin Author: | TWiki:Main.AndrewRJones![]() |
Previous Authors: | TWiki:Main.NicolasTisserand![]() ![]() |
Copyright: | © 2002-2014 TWiki:TWiki.TWikiContributor![]() |
License: | GPL (GNU General Public License![]() |
Plugin Version: | 2014-03-26 |
2014-03-26: | TWikibug:Item7470![]() |
2013-12-11: | TWikibug:Item7399![]() ![]() |
2013-04-04: | TWikibug:Item7211![]() ![]() |
2013-02-14: | TWikibug:Item7091![]() ![]() |
2013-02-13: | TWikibug:Item7091![]() ![]() |
2013-02-13: | TWikibug:Item7123![]() |
2012-11-15: | TWikibug:Item7035![]() ![]() |
2011-05-14: | TWikibug:Item6701![]() ![]() |
2010-10-23: | TWikibug:Item6530![]() ![]() ![]() |
2008-09-11: | TWikibug:Item5995![]() |
2002-07-12: | Initial version |
TWiki Dependency: | $TWiki::Plugins::VERSION 1.1 |
Dependencies: | enscript >= 1.6.3, CPAN:IPC::Run![]() |
Plugin Home: | http://TWiki.org/cgi-bin/view/Plugins/SyntaxHighlightingPlugin![]() |
Feedback: | http://TWiki.org/cgi-bin/view/Plugins/SyntaxHighlightingPluginDev![]() |
Appraisal: | http://TWiki.org/cgi-bin/view/Plugins/SyntaxHighlightingPluginAppraisal![]() |
Related Topics: VarCODE, TWikiPreferences, TWikiPlugins