SyntaxHighlightingPlugin

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

THIS WEBPAGE IS DEPRECATED - please visit our new website

Syntax Highlighting TWiki Plugin

The Syntax Highlighting Twiki Plugin is used to emphasize the rendering of your twiki 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 enable syntax highlighting on some text, just type :

%begin [numbered] language%

some text belonging to the language

%end% where language is one of the list above, and numbered an optional keyword triggering the line numbering feature.

Notice that the %begin language% and %end% must be left alone on one single line.

Example

The following text :

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

Syntax Highlighting: internal error

If you do not see a nice colorized piece of code above this, you should check if the plugin is well installed.

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

%begin numbered:10 sh% #!/bin/sh languages=`enscript --help-highlight | grep 'Name:' | cut -d ' ' -f 2` for l in $languages; do cat << EOF

  • $l
EOF done %end% which outputs:

Syntax Highlighting: internal error

SyntaxHighlightingPlugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %DEFAULTPLUGIN_SHORTDESCRIPTION%

  • One line description, is shown in the TextFormattingRules topic:
    • Set SHORTDESCRIPTION = This Plugin is used to emphasize the rendering of your twiki text according to several languages.

  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0

Plugin Installation Instructions

  • Make sure you have GNU enscript 1.6.3 or above installed.

  • Unzip the SyntaxHighlighting.zip package in your TWiki installation directory.

  • If the installation is correct, you should see some highlighted text in this page.

  • If you want support for additional languages (for customized or future enscript versions), you must edit the plugin file and add your languages to the languages array. (Make sure that your enscript version supports the languages you add.)

Known Bugs

Enscript oddities

%begin numbered sh% 
# youpi
%end% 

gives

Syntax Highlighting: internal error

Because enscript strangely adds an extra line (for closing its emphasizing markers) between the matched <pre> </pre> to its html output.

Working around such a weird behavior is ... not planned.

WikiWords on last line

%begin sh% UnmatchedWikiword? smile MatchedWikiWord? frown %end%

gives

Syntax Highlighting: internal error

Adding a newline at the end of input stops TWiki in his greedy matching, but this workaround is not an acceptable solution. Feel free to find another one ....

Plugin Info

Plugin Author: NicolasTisserand?, NicolasBurrus?, Perceval Anichini
Plugin Version: 12 Jul 2002
Change History: 12 Jul 2002: Initial version
CPAN Dependencies: none
Other Dependencies: GNU enscript 1.6.3
Perl Version: 5.0
Plugin Home: http://www.lrde.epita.fr/cgi-bin/twiki/view/TWiki/SyntaxHighlightingPlugin
Feedback: NicolasTisserand?

Related Topics: TWikiPreferences, TWikiPlugins, EmptyPlugin

-- NicolasTisserand? - 12 Jul 2002


Edit | Attach | Refresh | Diffs | More | Revision r1.1 - 20 Sep 2012 - 16:53 - Main.guest