Tags:
development1Add my vote for this tag rendering1Add my vote for this tag syntax_highlighting3Add my vote for this tag 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%
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 TWiki server.

  • For an automated installation, run the configure script and follow "Find More Extensions" in the in the Extensions section.
    • Optionally, move the lib/Beautifier, lib/Output and lib/HFile libraries into the Perl library folder.

  • Or, follow these manual installation steps:
    • Download the ZIP file from the Plugins home (see below).
    • Unzip BeautifierPlugin.zip in your twiki installation directory. Content:
      File: Description:
      data/TWiki/BeautifierPlugin.txt Plugin topic
      data/TWiki/VarCODE.txt CODE variable documentation topic
      pub/TWiki/BeautifierPlugin/style.css Default CSS
      lib/TWiki/Plugins/BeautifierPlugin.pm Plugin Perl module
      lib/Beautifier/*.pm Perl modules
      lib/HFile/*.pm Perl modules
      lib/Output/*.pm Perl modules
    • Optionally, move the lib/Beautifier, lib/Output and lib/HFile libraries into the Perl library folder.
    • Set the ownership of the extracted directories and files to the webserver user.

  • Plugin configuration and testing:
    • Run the configure script, enable the plugin in the Plugins section
    • Configure the plugin: See plugin settings above.
    • 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%

Plugin Info

Plugin Author: TWiki:Main.LingLo
Copyright: © 2002-2007 TWiki:Main.LingLo
© 2007-2012 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public License)
Plugin Version: 2012-12-02
Change History:  
2012-12-02: TWikibug:Item7020: Add category to VarCODE; doc improvements -- TWiki:Main.PeterThoeny
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: VarCODE, TWikiPreferences, TWikiPlugins

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 BeautifierPlugin.md5 r13 r12 r11 r10 r9 manage 0.2 K 2012-12-02 - 22:43 PeterThoeny  
Compressed Zip archivetgz BeautifierPlugin.tgz r13 r12 r11 r10 r9 manage 54.7 K 2012-12-02 - 22:42 PeterThoeny  
Compressed Zip archivezip BeautifierPlugin.zip r18 r17 r16 r15 r14 manage 71.9 K 2012-12-02 - 22:42 PeterThoeny  
Unknown file formatEXT BeautifierPlugin_installer r8 r7 r6 r5 r4 manage 4.3 K 2012-12-02 - 22:43 PeterThoeny  
Edit | Attach | Watch | Print version | History: r42 < r41 < r40 < r39 < r38 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r42 - 2013-10-16 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.