Syntax Highlighting Plugin

Emphasize the rendering of source code of many languages

Introduction

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.

Supported 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:

<sticky>
%CODE{lang="..." [num="10"]}% 
...code...
%ENDCODE%
</sticky>

The language can be any from the above list. The num setting is optional and will set the starting line number. The <sticky> tags are required to prevent TWiki's WYSIWYG editor from removing line breaks inside the code block.

Examples

The following text:

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

gives (if installed):

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

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):

   10	#!/bin/sh
   11	languages=`enscript --help-highlight | grep 'Name:' | cut -d ' ' -f 2`
   12	for l in $languages; do
   13	    cat << EOF
   14	   * $l
   15	EOF
   16	done

Plugin Settings

Use configure to change the settings for this plugin.

Change of Syntax

Older version of 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: 21287 (2011-05-14)
Change History:  
2011-05-14: TWikibug:Item6701: Small fix in Config.spec -- TWiki:Main.PeterThoeny
2010-10-23: TWikibug:Item6530: Doc improvements - TWiki:Main.PeterThoeny, TWiki:Main.AndreasKeil
2008-09-11: TWikibug:Item5995: Rewritten to work on TWiki 4.2
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: TWikiPreferences, TWikiPlugins

Tags:
create new tag
, view all tags
Topic revision: r1 - 2011-05-15 - 06:22:40 - TWikiContributor

 
  • Search: 
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