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 |
XML |
%CODE{"xml"}% ... %ENDCODE% |
Visual Basic |
%CODE{"vb"}% ... %ENDCODE% |
VHDL |
%CODE{"vhdl"}% ... %ENDCODE% |
Verilog |
%CODE{"verilog"}% ... %ENDCODE% |
TCL |
%CODE{"tcl"}% ... %ENDCODE% |
Scheme |
%CODE{"scheme"}% ... %ENDCODE% |
Python |
%CODE{"python"}% ... %ENDCODE% |
PL/SQL |
%CODE{"plsql"}% ... %ENDCODE% |
PHP3 |
%CODE{"php3"}% ... %ENDCODE% |
Perl |
%CODE{"perl"}% ... %ENDCODE% |
Makefile |
%CODE{"makefile"}% ... %ENDCODE% |
Lua |
%CODE{"lua"}% ... %ENDCODE% |
JavaScript |
%CODE{"javascript"}% ... %ENDCODE% |
Java |
%CODE{"java"}% ... %ENDCODE% |
IDL |
%CODE{"idl"}% ... %ENDCODE% |
HTML |
%CODE{"html"}% ... %ENDCODE% |
CSS |
%CODE{"css"}% ... %ENDCODE% |
Corba |
%CODE{"corba"}% ... %ENDCODE% |
C++ |
%CODE{"cpp"}% ... %ENDCODE% |
C# |
%CODE{"csharp"}% ... %ENDCODE% |
bash |
%CODE{"bash"}% ... %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/![](/twiki/pub/TWiki/TWikiDocGraphics/external-link.gif)
and converting the relevant language file from PHP to Perl. Note: The original
http://www.beautifier.org/![](/twiki/pub/TWiki/TWikiDocGraphics/external-link.gif)
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