Tags:
create new tag
, view all tags

BeautifierPlugin

Highlight and format source code fragments of various languages

Introduction

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%
Corba %CODE{"corba"}% ... %ENDCODE%
CSS %CODE{"css"}% ... %ENDCODE%
HTML %CODE{"html"}% ... %ENDCODE%
IDL %CODE{"idl"}% ... %ENDCODE%
Java %CODE{"java"}% ... %ENDCODE%
JavaScript %CODE{"javascript"}% ... %ENDCODE%
Lua %CODE{"lua"}% ... %ENDCODE%
Makefile %CODE{"makefile"}% ... %ENDCODE%
Perl %CODE{"perl"}% ... %ENDCODE%
PHP3 %CODE{"php3"}% ... %ENDCODE%
PL/SQL %CODE{"plsql"}% ... %ENDCODE%
Python %CODE{"python"}% ... %ENDCODE%
Scheme %CODE{"scheme"}% ... %ENDCODE%
TCL %CODE{"tcl"}% ... %ENDCODE%
HTML %CODE{"html"} ... %ENDCODE%
Visual Basic %CODE{"vb"}% ... %ENDCODE%
Verilog %CODE{"verilog"}% ... %ENDCODE%
VHDL %CODE{"vhdl"}% ... %ENDCODE%
XML %CODE{"xml"}% ... %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 http://sourceforge.net/projects/beautifier/ and converting the relevant language file from PHP to Perl. Note: The original http://www.beautifier.org/ website is defunct.

Display Customisation

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

Examples

%CODE{"cpp"}%
   void foo() {
     print("Do stuff.\n");
   }
%ENDCODE%

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 = Highlight and format source code fragments of various languages

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 BeautifierPlugin.zip in your twiki installation directory, this will also install the Beautifier library by default. Content:
    File: Description:
    data/TWiki/BeautifierPlugin.txt  
    data/TWiki/VarCODE.txt  
    lib/Beautifier/Context.pm  
    lib/Beautifier/Core.pm  
    lib/Beautifier/HFile.pm  
    lib/Beautifier/Magic.pm  
    lib/Beautifier/MagicConfig.pm  
    lib/HFile/HFile_bash.pm  
    lib/HFile/HFile_corba.pm  
    lib/HFile/HFile_cpp.pm  
    lib/HFile/HFile_csharp.pm  
    lib/HFile/HFile_css.pm  
    lib/HFile/HFile_html.pm  
    lib/HFile/HFile_idl.pm  
    lib/HFile/HFile_java.pm  
    lib/HFile/HFile_javascript.pm  
    lib/HFile/HFile_lua.pm  
    lib/HFile/HFile_makefile.pm  
    lib/HFile/HFile_perl.pm  
    lib/HFile/HFile_php3.pm  
    lib/HFile/HFile_plsql.pm  
    lib/HFile/HFile_python.pm  
    lib/HFile/HFile_scheme.pm  
    lib/HFile/HFile_tcl.pm  
    lib/HFile/HFile_verilog.pm  
    lib/HFile/HFile_vb.pm  
    lib/HFile/HFile_vhdl.pm  
    lib/HFile/HFile_xml.pm  
    lib/Output/ANSI.pm  
    lib/Output/DocBook.pm  
    lib/Output/HTML.pm  
    lib/TWiki/Plugins/BeautifierPlugin.pm  
    pub/TWiki/BeautifierPlugin/style.css  

    • Optionally, move the lib/Beautifier, lib/Output and lib/HFile libraries into the Perl library folder.
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.
  • Test if the installation was successful:

#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);
        }
}

BeautifierPlugin Error: Unable to handle "unknown" language.

	testing an invalid language setting...

Plugin Info

Plugin Author: TWiki:Main.LingLo
Copyright: © 2002-2007 TWiki:Main.LingLo
© 2007-2010 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public License)
Plugin Version: 2011-01-03
Change History:  
2011-01-03: TWikibug:Item6530: Doc improvements; small style improvement; changing TWIKIWEB to SYSTEMWEB; adding CORBA (thanks Will Norris), IDL (thanks Will Norris), Visual Basic (thanks TWiki:Main.ThomasJachmann), CSS -- TWiki:Main.PeterThoeny
2007-05-20: added JavaScript language file, removed legacy CODE_lang construct -- TWiki:Main.WillNorris
2007-04-30: warnings cleanup; no functional changes -- TWiki:Main.WillNorris
2007-04-27: automatically adds CSS for formatting code fragments -- TWiki:Main.WillNorris
2006-01-01: upgraded to TWiki::Func::extractNameValuePair for better parameter parsing, upgraded TWiki:Plugins.BuildContrib support -- TWiki:Main.WillNorris
2003-07-26: Syntax fixes from TWiki:Main.WillNorris -- TWiki:Main.LingLo
2003-02-26: Syntax fix from TWiki:Main.JoshMore -- TWiki:Main.LingLo
2002-12-28: Accepts mixed case language names -- TWiki:Main.LingLo
2002-12-20: Changed syntax to allow for simpler addition of new languages -- TWiki:Main.LingLo
2002-10-16: Added nebula nodes and links to Python scripts, but it doesn't work since the node names are usually in strings -- TWiki:Main.LeafGarland
2002-07-30: Added nebula nodes and links to TCL scripts -- TWiki:Main.LeafGarland
2002-07-30: Changed Beautifier::Core to use 'linkscripts' -- TWiki:Main.LeafGarland
2002-07-28: Created -- TWiki:Main.LingLo
CPAN Dependencies: none
Other Dependencies: none (Beautifier is included)
Perl Version: 5.005
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/BeautifierPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/BeautifierPluginDev

Related Topics: TWikiPreferences, TWikiPlugins

Topic attachments
I Attachment Action Size Date Who Comment
Cascading Style Sheet filecss style.css manage 0.2 K 04 Jan 2011 - 00:42 TWikiAdminUser Saved by install script

Physics WebpagesRHUL WebpagesCampus Connect • Royal Holloway, University of London, Egham, Surrey TW20 0EX; Tel/Fax +44 (0)1784 434455/437520

Topic revision: r2 - 01 Oct 2012 - TWikiAdminUser

 
This site is powered by the TWiki collaboration platformCopyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.BeautifierPlugin.