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:
#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
Related Topics: VarCODE,
TWikiPreferences,
TWikiPlugins