This plugin allows you to have code fragments automatically formatted and highlighted. It uses the Beautifier library (included) written by Mike Jewell.

Syntax Rules

  • Insert the code between %CODE{"language"}% and %ENDCODE%. The following table indicates the values used for the different languages:

Language Syntax
bash %CODE{"bash"}% ... %ENDCODE%
C++ %CODE{"cpp"}% ... %ENDCODE%
C# %CODE{"csharp"}% ... %ENDCODE%
Java %CODE{"java"}% ... %ENDCODE%
JavaScript %CODE{"javascript"}% ... %ENDCODE%
Lua %CODE{"lua"}% ... %ENDCODE%
Makefile %CODE{"makefile"}% ... %ENDCODE%
Perl %CODE{"perl"}% ... %ENDCODE%
PL/SQL %CODE{"plsql"}% ... %ENDCODE%
Python %CODE{"python"}% ... %ENDCODE%
PHP3 %CODE{"php3"}% ... %ENDCODE%
Scheme %CODE{"scheme"}% ... %ENDCODE%
TCL %CODE{"tcl"}% ... %ENDCODE%
HTML %CODE{"html"} ... %ENDCODE%
XML %CODE{"xml"}% ... %ENDCODE%
Verilog %CODE{"verilog"}% ... %ENDCODE%
VHDL %CODE{"vhdl"}% ... %ENDCODE%

Additional languages can be added since the Beautifier library is flexible and can support a wide range of language families. Other languages can be added with relative ease by downloading the full PHP dist from and converting the relevant language file from PHP to Perl.

Display Customisation

The code fragments are formaated using CSS. To change the look, upload a new version of style.css to this topic.


   void foo() {
     print("Do stuff.\n");

BeautifierPlugin Global Settings

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

  • One line description, is shown in the TextFormattingRules topic:
    • Set SHORTDESCRIPTION = Highlights and formats code fragments

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running.

  • Download the ZIP file from the Plugin web (see below)
  • Unzip in your twiki installation directory, this will also install the Beautifier library by default. Content:
  • (Dakar) Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.
  • To install the Beautifier library, either install it in the Perl library folder or unpack it into the twiki directory. For the latter, the following files are installed:
    File: Description:
    data/TWiki/BeautifierPlugin.txt NEW
    data/TWiki/VarCODE.txt NEW
    lib/Beautifier/ NEW
    lib/Beautifier/ NEW
    lib/Beautifier/ NEW
    lib/Beautifier/ NEW
    lib/Beautifier/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/HFile/ NEW
    lib/Output/ NEW
    lib/Output/ NEW
    lib/Output/ NEW
    lib/TWiki/Plugins/ NEW
    pub/TWiki/BeautifierPlugin/style.css NEW

  • Test if the installation was successful:

%CODE{"cpp"}% #include <nworld.h>

/** @brief Advance the simulation by one timeslice. */ void nWorld::StepSim() { // Iterate simulation loop for (node = entityList.GetHead(); node = NULL; node = node->GetSucc()) { entity = (nEntity*)node->GetPtr(); entity->Trigger(this, this->stepSize); } } %ENDCODE%

%CODE{"unknown"}% testing an invalid language setting... %ENDCODE%


Date Change Name
20 May 2007 added JavaScript language file, removed legacy CODE_lang construct TWiki:Main.WillNorris
30 Apr 2007 warnings cleanup; no functional changes TWiki:Main.WillNorris
27 Apr 2007 automatically adds CSS for formatting code fragments TWiki:Main.WillNorris
1 Jan 2006 upgraded to TWiki::Func::extractNameValuePair for better parameter parsing, upgraded TWiki:Plugins.BuildContrib support TWiki:Main.WillNorris
26 Jul 2003 Syntax fixes from TWiki:Main/WillNorris TWiki:Main/LingLo
10 Feb 2003 Syntax fix from TWiki:Main/JoshMore TWiki:Main/LingLo
28 Dec 2002 Accepts mixed case language names TWiki:Main/LingLo
20 Dec 2002 Changed syntax to allow for simpler addition of new languages TWiki:Main/LingLo
16 Oct 2002 Added nebula nodes and links to Python scripts, but it doesn't work since the node names are usually in strings TWiki:Main/LeafGarland
30 Jul 2002 Added nebula nodes and links to TCL scripts TWiki:Main/LeafGarland
30 Jul 2002 Changed Beautifier::Core to use 'linkscripts' TWiki:Main/LeafGarland
28 Jul 2002 Created TWiki:Main/LingLo

Plugin Info

Plugin Author: TWiki:Main/LingLo
Plugin Version: 27 Apr 2007
CPAN Dependencies: none
Other Dependencies: Beautifier (supplied)
Perl Version: 5.005
Plugin Home:

Related Topics: TWikiPreferences, TWikiPlugins

-- TWiki:Main.LingLo - 18 Dec 2002

Topic attachments
I Attachment History Action Size Date Who Comment
Cascading Style Sheet filecss style.css   manage 0.2 K 2007-04-28 - 13:01 TWikiContributor CSS to format code fragments
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2007-04-28 - TWikiContributor
This site is powered by the TWiki collaboration platform Powered by Perl 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 KoreaCmsWiki? Send feedback
Note: Please contribute updates to this topic on at TWiki:TWiki.BeautifierPlugin