Need help?

Contact SCC

Email scicomp
Join #scicomp on Slack

Help us help you

Follow these guidelines when submitting a help request.

You are here: System » SyntaxHighlightingPlugin

SyntaxHighlightingPlugin

30 Sep 2022 - 18:13 | Version 14 |

This Plugin is used to emphasize the rendering of your wiki text according to several languages.

This plugin was modified at FI to use highlight rather than enscript: this enables the support of many more languages, and easy customization. http://www.andre-simon.de/doku/highlight/en/highlight.php

If you want to change which theme is used to display the code excerpts, go to your user account page WikiGuest and set the preference field HIGHLIGHT_THEME_FILE (current theme: %HIGHLIGHT_THEME_FILE%) These themes apply only to you as you are looking at topics. Any file attached to this page can be used. The naming convention is highlight.theme_name.css

Description

The Syntax Highlighting Plugin is used to emphasize the rendering of your wiki text according to several languages.

It uses highlight to render its output.

It supports the following languages :
  • ABAP/4 : abap4
  • ABC : abc
  • Advanced Backus-Naur Form : abnf
  • ActionScript : actionscript
  • ADA95 : ada
  • Agda : agda
  • ALGOL 68 : algol
  • AMPL : ampl
  • AMTrix : amtrix
  • AppleScript : applescript
  • Arc : arc
  • ARM : arm
  • AS/400 CL : as400cl
  • ASCEND : ascend
  • Active Server Pages : asp
  • Abstract : aspect
  • Generic Assembler : assembler
  • Applied Type System : ats
  • AutoHotKey : autohotkey
  • AutoIt : autoit
  • Avenue : avenue
  • (G)AWK : awk
  • DOS Batch : bat
  • BBcode : bbcode
  • BCPL : bcpl
  • BibTeX : bibtex
  • Biferno : biferno
  • Bison : bison
  • Blitz Basic : blitzbasic
  • BM Script : bms
  • Backus-Naur Form : bnf
  • Boo : boo
  • C and C++ : c, cpp
  • Ceylon : ceylon
  • Charmm : charmm
  • CHILL : chill
  • Chapel : chpl
  • Clean : clean
  • ClearBasic : clearbasic
  • Clipper : clipper
  • Clojure : clojure
  • Clips : clp
  • CMake : cmake
  • COBOL : cobol
  • Coffeescript : coffee
  • ColdFusion MX : coldfusion
  • Generic config files : conf
  • Console : console
  • Crack : crk
  • Coffeescript Block Regex : cs_block_regex
  • C# : csharp
  • CSS : css
  • D : d
  • Dart : dart
  • Diff : diff
  • Dockerfile : docker
  • Device Tree Source : dts
  • Dylan : dylan
  • Extended Backus-Naur Form : ebnf
  • EBNF2 : ebnf2
  • Eiffel : eiffel
  • Elixir : elixir
  • E-Mail treated as Markup : email
  • Erlang : erlang
  • Euphoria : euphoria
  • Express : express
  • FAME : fame
  • fasm : fasm
  • Felix : felix
  • Fortran 77 : fortran77
  • Fortran 90 : fortran90
  • Frink : frink
  • F# : fsharp
  • fstab config file : fstab
  • Java FX : fx
  • Gambas : gambas
  • gdb : gdb
  • GDScript : gdscript
  • Go : go
  • Graphviz : graphviz
  • Haskell : haskell
  • haXe : haxe
  • Hecl : hcl
  • HTML : html
  • Apache Config : httpd
  • Icon : icon
  • IDL : idl
  • Interactive Data Language : idlang
  • Lua : inc_luatex
  • Informix : informix
  • INI : ini
  • Inno Setup : innosetup
  • INTERLIS : interlis
  • IO : io
  • Jasmin : jasmin
  • Java : java
  • Javascript : js
  • Javascript Regex : js_regex
  • JSON : json
  • JavaServer Pages : jsp
  • JSX : jsx
  • Julia : julia
  • Kotlin : kotlin
  • LDAP : ldif
  • LESS : less
  • Haskell LHS : lhs
  • Lilypond : lilypond
  • Limbo : limbo
  • Linden Script : lindenscript
  • Lisp : lisp
  • Logtalk : logtalk
  • Lotos : lotos
  • Lotus : lotus
  • Lua : lua
  • Luban : luban
  • Make : make
  • Maple : maple
  • Matlab : matlab
  • Maya : maya
  • GitHub Flavored Markdown : md
  • Mercury : mercury
  • Miranda : miranda
  • Modula2 : mod2
  • Modula3 : mod3
  • Modelica : modelica
  • MoonScript : moon
  • MaxScript : ms
  • mIRC Scripting : msl
  • MSSQL : mssql
  • Magic eXtensible Markup : mxml
  • Notation3, N-Triples, Turtle, SPARQL: n3
  • Nasal : nasal
  • NeXT Byte Codes : nbc
  • Nemerle : nemerle
  • NetRexx : netrexx
  • Nginx configuration : nginx
  • Nice : nice
  • Nim : nim
  • NSIS : nsis
  • Not eXactly C : nxc
  • Oberon : oberon
  • Objective C : objc
  • Objective Caml : ocaml
  • Octave : octave
  • OpenObjectRexx : oorexx
  • Object Script : os
  • Oz : oz
  • Paradox : paradox
  • Pascal : pas
  • Portable Document Format : pdf
  • Perl : perl
  • PHP : php
  • Pike : pike
  • PL/1 : pl1
  • PL/Perl : plperl
  • PL/Python : plpython
  • PL/Tcl : pltcl
  • PO translation : po
  • Polygen : polygen
  • Pony : pony
  • POV-Ray : pov
  • Prolog : pro
  • Progress : progress
  • PostScript : ps
  • Microsoft PowerShell : ps1
  • PATROL : psl
  • Pure : pure
  • PureBASIC : purebasic
  • Pyrex : pyrex
  • Python : python
  • Python console : pythonconsole, pycon
  • Qore : q
  • QMake Project : qmake
  • QML : qml
  • Qu : qu
  • R : r
  • Rebol : rebol
  • Rexx : rexx
  • Relax NG : rnc
  • RPG : rpg
  • RPL Programming Language : rpl
  • Rust : rs
  • Ruby : ruby
  • PowerPC Assembler : s
  • SAS : sas
  • Scala : scala
  • Scilab : scilab
  • SASS/SCSS : scss
  • Bash : sh
  • SMALL : small
  • Smalltalk : smalltalk
  • Standard ML : sml
  • SNMP : snmp
  • SNOBOL : snobol
  • RPM Spec : spec
  • SPIN SQL : spn
  • PL/SQL : sql
  • Squirrel : squirrel
  • Stylus : styl
  • SVG : svg
  • Swift : swift
  • Sybase SQL : sybase
  • Tcl/Tk : tcl
  • TCSH : tcsh
  • TeX and LaTeX : tex
  • TypeScript : ts
  • Transact-SQL : tsql
  • TTCN3 : ttcn3
  • Plain text : txt
  • UPC : upc
  • Vala : vala
  • Visual Basic : vb
  • Verilog : verilog
  • VHDL : vhd
  • vimscript : vimscript
  • Whiley : whiley
  • XML : xml
  • SuperX++ : xpp
  • Yaiff : yaiff
  • Ansible YAML : yaml
  • Yang : yang
  • Zonnon : znn

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 Foswiki's WYSIWYG editor from removing line breaks inside the code block.

Using SyntaxHighlightingPlugin With Other Syntax Highlighters

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_ENSCRIPT% 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 [Foswikitask:Item1353][task report]].

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 &lt;&lt; "Hello, world." &lt;&lt; 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 &lt;&lt; EOF
   14    * $l
   15 EOF
   16 done

Change of Syntax

This plugin used to use the following syntax (pre September 2008):
<sticky>
%begin sh%
...code...
%end%
</sticky>

This has been changed to be more consistent with other Foswiki 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!

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.

You should ensure the path to enscript is correctly set in configure before enabling the plugin.

Plugin Files

File: Description:Sorted ascending
lib/Foswiki/Plugins/SyntaxHighlightingPlugin/Config.spec Configure Spec
lib/Foswiki/Plugins/SyntaxHighlightingPlugin.pm Perl Module
data/System/SyntaxHighlightingPlugin.txt Plugin Topic
tools/SyntaxHighlightingPlugin_covert.pl Script to convert from old syntax to new

Plugin Info

Plugin Author(s): Foswiki:Main.AndrewJones
Previous Author(s): TWiki:Main.NicolasTisserand, TWiki:Main.NicolasBurrus, Perceval Anichini
Copyright: © 2008 - 2009, Andrew Jones, © 2000 - 2001, Andrea Sterbini, © 2001, Peter Theony
License: GPL (GNU General Public License)
Plugin Release: 1.21
Plugin Version: 9720 (2010-10-25)
Change History:
25 Oct 2010: 1.21: Documentation updates. -- Foswiki:Main.AndreasKeil, Foswiki:Main.WillNorris
07 Jun 2009: 1.2: Fixed rendering in numbered lists (Foswikitask:Item8176); Moved configure setting to Extensions heading -- Foswiki:Main.AndrewJones
29 Mar 2009: 1.1: Added %CODE_ENSCRIPT% syntax so it can be used with other syntax highlighters (Foswikitask:Item1353) -- Foswiki:Main.AndrewJones
17 Mar 2009: 1.0: Initial release for Foswiki (Foswikitask:Item1251) -- Foswiki:Main.AndrewJones
11 Sep 2008: Rewritten to work on TWiki 4.2 (TWikibug:Item5995) -- Foswiki:Main.AndrewJones
12 Jul 2002: Initial version
Dependencies:
NameVersionDescription
IPC::Run >0 Required
enscript >1.6.4 Required. Known to work with version 1.6.4 and not with 1.6.1
Plugin Home: http://foswiki.org/Extensions/SyntaxHighlightingPlugin
Support: http://foswiki.org/Support/SyntaxHighlightingPlugin
Related Topics: DefaultPreferences, SitePreferences, Plugins

Copyright © Simons Foundation. All material on this collaboration platform is the property of the Simons Foundation.
This website is using cookies. More info. That's Fine