SourceHighlightPlugin
This plugin allows you to have code fragments automatically formatted and highlighted using the
GNU source-highlight package.
- Just paste the code between %CODE{"syntax"}% and %ENDCODE%. The following indicates the syntax used for the different languages:
| Language |
Key |
Syntax |
| C++ |
cpp |
%CODE{"cpp"}% ... %ENDCODE% |
| C |
cpp |
%CODE{"cpp"}% ... %ENDCODE% |
| Flex |
flex |
%CODE{"flex"}% ... %ENDCODE% |
| Java |
java |
%CODE{"java"}% ... %ENDCODE% |
| Perl |
perl |
%CODE{"perl"}% ... %ENDCODE% |
| PHP3 |
php3 |
%CODE{"php3"}% ... %ENDCODE% |
| Prolog |
prolog |
%CODE{"prolog"}% ... %ENDCODE% |
| Python |
python |
%CODE{"python"}% ... %ENDCODE% |
You can also define a default language and use the shortcut:
%CODE% ...
%ENDCODE%
%CODE{"cpp"}%
void foo() {
print("Do stuff.\n");
}
%ENDCODE%
Plugin settings are stored as preferences variables. To reference a plugin setting write
%<plugin>_<setting>%, i.e.
%SOURCEHIGHLIGHTPLUGIN_DEFAULTLANGUAGE%
- One line description, is shown in the TextFormattingRules topic:
- Set SHORTDESCRIPTION = Highlights and formats code fragments using GNU source-highlight.
- Set DEBUG = 0
- Full path to GNU source-highlight binary (REQUIRED)
- Set BINARY = /usr/local/bin/source-highlight
- Language to use when none specified (optional); choose from one of the Key values in the table above
- Set DEFAULTLANGUAGE = java
- CSS class to use for the
div tag surrounding the HTML output; if undefined we use codefragment
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.
- Install the GNU source-highlight package and note its location
- Open /usr/local/shard/source-highlight/html.outlang. Eliminate all <tt> </tt>s. Because in my browser Firefox 3, it results in a blank line ahead of my code.
- Download the ZIP file from the Plugin web (see below)
- Unzip
SourceHighlightPlugin.zip in your twiki installation directory. Content:
|
|
| File: |
Description: |
data/TWiki/SourceHighlightPlugin.txt |
Both the plugin topic and the configuration file |
lib/TWiki/Plugins/SourceHighlightPlugin.pm |
Plugin Perl module |
|
|
|
- To get a smart-looking box around the code fragment, something like the following is needed in the skin's stylesheet. Note that you may need to change the class name if you modify the FORMATCLASS configuration variable above.
.codefragment {
background : #FFFFCC;
border : 1px solid #CCCCCC;
margin-left : 2em;
margin-right : 2em;
padding : 4px;
}
- Test if the installation was successful:
%CODE{"java"}%
package com.foo.stuff;
import java.util.ArrayList;
import java.util.List;
public class Thingy
{
private List myList;
public Thingy()
{
myList = new
ArrayList ();
}
/**
* @param count This is the thingy you want.
*/
public String getThingy( int count )
{
return (String)myList.get( count );
}
}
%ENDCODE%
Related Topics: TWikiPreferences,
TWikiPlugins
--
ChrisWinters - 23 Jan 2003
Topic revision: r13 - 2009-04-10 - 21:18:12 -
PeterThoeny