Syntax Highlighting Plugin

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.

It supports the following languages :

  • ada
  • asm
  • awk
  • bash
  • c
  • changelog
  • c++
  • csh
  • delphi
  • diff
  • diffs
  • diffu
  • elisp
  • fortran
  • fortran_pp
  • haskell
  • html
  • idl
  • inf
  • java
  • javascript
  • ksh
  • m4
  • mail
  • makefile
  • maple
  • matlab
  • modula_2
  • nested
  • nroff
  • objc
  • outline
  • pascal
  • perl
  • postscript
  • python
  • rfc
  • scheme
  • sh
  • skill
  • sql
  • states
  • synopsys
  • tcl
  • tcsh
  • tex
  • vba
  • verilog
  • vhdl
  • vrml
  • wmlscript
  • zsh

Syntax Rules

To use this plugin, use the following syntax:

%CODE{lang="..." [num="10"]}% 
...code...
%ENDCODE%

The language can be any from the above list. The num setting is optional and will set the starting line number.

Examples

The following text :

 
%CODE{"c++"}%
#include <iostream>
int main()
{
  std::cout << "Hello, world." << std::endl;
}
%ENDCODE%

gives (if installed):

%CODE{"c++"}% #include int main() { std::cout << "Hello, world." << std::endl; } %ENDCODE%

You can also output numbered lines starting at 10 with this text:

%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% 

gives (if installed):

%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%

Plugin Settings

Use configure to change the settings for this plugin.

Change of Syntax

This plugin used to use the following syntax:

%begin sh%
...code...
%end%

This has been changed to be more consistent with other twiki variables. There is a script included which will replace the old syntax with the new. To use it, copy it from the 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!

Plugin 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 where TWiki is running.

Like many other TWiki extensions, this module is shipped with a fully automatic installer script written using the BuildContrib.

  • If you have TWiki 4.2 or later, you can install from the configure interface (Go to Plugins->Find More Extensions)
  • If you have any problems, then you can still install manually from the command-line:
    1. Download one of the .zip or .tgz archives
    2. Unpack the archive in the root directory of your TWiki installation.
    3. Run the installer script ( perl <module>_installer )
    4. Run configure and enable the module, if it is a plugin.
    5. Repeat for any missing dependencies.
  • If you are still having problems, then instead of running the installer script:
    1. Make sure that the file permissions allow the webserver user to access all files.
    2. Check in any installed files that have existing ,v files in your existing install (take care not to lock the files when you check in)
    3. Manually edit LocalSite.cfg to set any configuration variables.

Plugin Files

data/TWiki/SyntaxHighlightingPlugin.txt Plugin Topic
lib/TWiki/Plugins/SyntaxHighlightingPlugin.pm Perl Module
lib/TWiki/Plugins/SyntaxHighlightingPlugin/Config.spec  
tools/SyntaxHighlightingPlugin_covert.pl  

Plugin Info

Plugin Author: TWiki:Main.AndrewRJones
Previous Authors: TWiki:Main.NicolasTisserand, TWiki:Main.NicolasBurrus, Perceval Anichini
License: GPL (GNU General Public License)
Plugin Version: 17497 (12 Dec 2008)
Change History:  
11 Sep 2008 Bugs:Item5995 - Rewritten to work on TWiki 4.2
12 Jul 2002: Initial version
TWiki Dependency: $TWiki::Plugins::VERSION 1.1
Dependencies: enscript, 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: TWikiPreferences, TWikiPlugins

Topic revision: r4 - 2009/05/12 - 03:41:32 - TWikiAdminUser
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.SyntaxHighlightingPlugin