BeautifierPlugin
This plugin allows you to have code fragments automatically formatted and highlighted. It depends on the
Beautifier library written by Mike Jewell.
Syntax Rules
- Just paste the code between %CODE{"syntax"}% and %ENDCODE%. The following indicates the syntax used for the different languages:
| Language | Syntax |
| bash | %CODE{"bash"}% ... %ENDCODE% |
| C++ | %CODE{"cpp"}% ... %ENDCODE% |
| C# | %CODE{"csharp"}% ... %ENDCODE% |
| Java | %CODE{"java"}% ... %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 easy by downloading the full PHP dist from
http://www.beautifier.org and converting the relevant language file from PHP to Perl.
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.
%INTERWIKIPLUGIN_SHORTDESCRIPTION%
- One line description, is shown in the Text Formatting Rules 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
BeautifierPlugin.zip in your twiki installation directory, this will also install the Beautifier library by default. Content: | File: | Description: |
data/TWiki/BeautifierPlugin.txt | Plugin topic |
data/TWiki/BeautifierPlugin.txt,v | Plugin topic repository |
lib/TWiki/Plugins/BeautifierPlugin.pm | Plugin Perl module |
- (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:
%$MANIFEST%
- To get the doxygen-ish box around the code fragment, the following is needed in the skin's stylesheet:
div.fragment{
background : #FFFFCC;
border : 1px solid #CCCCCC;
margin-left : 2em;
margin-right : 2em;
padding : 4px;
}
- 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%
Bugs
- Why doesn't it highlight Tcl keywords with 3 spaces in front? See Audio Example?, the first code snippet has 4 space indents the rest have 3.
-- TWiki:Main/LeafGarland 31 Jul 2002
History
Plugin Info
Related Topics: T Wiki Preferences,
T Wiki Plugins
--
TWiki:Main.LingLo - 18 Dec 2002