TWiki
>
TWiki Web
>
SourceHighlightPlugin
(2024-03-02,
TWikiAdminUser
)
(raw view)
E
dit
A
ttach
Tags:
create new tag
view all tags
---+ <nop>%TOPIC% <!-- Contributions to this plugin are appreciated. Please update the plugin page at http://twiki.org/cgi-bin/view/Plugins/SourceHighlightPlugin or provide feedback at http://twiki.org/cgi-bin/view/Plugins/SourceHighlightPluginDev. If you are a TWiki contributor please update the plugin in the SVN repository. the current web --> %SHORTDESCRIPTION% <sticky><div style="float:right; background-color:#eeeeee; margin:0 0 20px 20px; padding: 0 10px 0 10px; width:380px"> %TOC{title="Page contents"}% </div></sticky> ---++ Introduction This plugin allows you to have code fragments automatically formatted and highlighted using the [[http://www.gnu.org/software/src-highlite/][GNU source-highlight]] package. ---++ Syntax Rules * Just paste the code between %<nop>CODE{"syntax"}% and %ENDCODE%. The following indicates the syntax used for the different languages: <blockquote> | *Language* | *Key* | *Syntax* | | C++ | cpp | =%<nop>CODE{"cpp"}%= ... =%ENDCODE%= | | C | cpp | =%<nop>CODE{"cpp"}%= ... =%ENDCODE%= | | Flex | flex | =%<nop>CODE{"flex"}%= ... =%ENDCODE%= | | Java | java | =%<nop>CODE{"java"}%= ... =%ENDCODE%= | | Perl | perl | =%<nop>CODE{"perl"}%= ... =%ENDCODE%= | | PHP3 | php3 | =%<nop>CODE{"php3"}%= ... =%ENDCODE%= | | Prolog | prolog | =%<nop>CODE{"prolog"}%= ... =%ENDCODE%= | | Python | python | =%<nop>CODE{"python"}%= ... =%ENDCODE%= | </blockquote> You can also define a default language and use the shortcut: =%<nop>CODE%= ... =%ENDCODE%= ---++ Example <pre> %<nop>CODE{"cpp"}% void foo() { print("Do stuff.\n"); } %ENDCODE% </pre> ---++ <nop>%TOPIC% Global Settings Plugin settings are stored as preferences variables. To reference a plugin setting write ==%<nop><plugin>_<setting>%==, i.e. ==%<nop>SOURCEHIGHLIGHTPLUGIN_DEFAULTLANGUAGE%== * One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: * Set SHORTDESCRIPTION = Highlight and format code fragments using GNU source-highlight * Set DEBUG = 0 * Full path to GNU source-highlight binary (*REQUIRED*) * Set BINARY = /usr/bin/source-highlight * Language to use when none specified (optional); choose from one of the *Key* values in the table above * Set DEFAULTLANGUAGE = cpp * CSS class to use for the =div= tag surrounding the HTML output; if undefined we use *codefragment* * Set FORMATCLASS = ---++ 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. * Install the GNU source-highlight package and note its location * Open /usr/local/shard/source-highlight/html.outlang. Eliminate all <tt> </tt>s. This avoids a blank line at the beginning of the code. * Download the ZIP file from the Plugin web (see below) * Unzip ==%TOPIC%.zip== in your twiki installation directory. Content: | *File:* | *Description:* | | ==data/TWiki/%TOPIC%.txt== | Plugin topic | | ==lib/TWiki/Plugins/%TOPIC%.pm== | Plugin Perl module | * Visit =configure= in your TWiki installation, and enable the plugin in the {Plugins} section. * 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. <blockquote> <pre> .codefragment { background : #FFFFCC; border : 1px solid #CCCCCC; margin-left : 2em; margin-right : 2em; padding : 4px; } </pre> </blockquote> * Test if the installation was successful: %CODE% 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% ---++ Plugin Info | Plugin Author: | TWiki:Main.ChrisWinters | | Copyright: | © 2003 TWiki:Main.ChrisWinters, %BR% © 2003-2010 TWiki:TWiki.TWikiContributor | | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | | Plugin Version: | 19332 (2010-08-06) | | Change History: | <!-- versions below in reverse order --> | | 2010-08-06: | TWikibug:Item6530 - doc enhancements; changing TWIKIWEB to SYSTEMWEB -- TWiki:Main.PeterThoeny | | 2009-02-10: | Fix for last bracket missing; fixed default language, changing from DEFAULTLANG to DEFAULTLANGUAGE -- TWiki:Main.FengZhaolin | | 2003-01-23: | Adapted from TWiki:Plugins.BeautifierPlugin -- TWiki:Main.ChrisWinters | | CPAN Dependencies: | none | | Other Dependencies: | [[http://www.gnu.org/software/src-highlite/][GNU source-highlight]] | | Perl Version: | 5.005 | | Plugin Home: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC% | | Feedback: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev | __Related Topics:__ %SYSTEMWEB%.TWikiPreferences, %SYSTEMWEB%.TWikiPlugins
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r3 - 2024-03-02
-
TWikiAdminUser
TWiki
Log In
or
Register
TWiki Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
User Reference
ATasteOfTWiki
TextFormattingRules
TWikiVariables
FormattedSearch
QuerySearch
TWikiDocGraphics
TWikiSkinBrowser
InstalledPlugins
Admin Maintenance
Reference Manual
AdminToolsCategory
InterWikis
ManagingWebs
TWikiSiteTools
TWikiPreferences
WebPreferences
Categories
Admin Documentation
Admin Tools
Developer Doc
User Documentation
User Tools
Webs
Blog
TWiki
ZMobile
Copyright © 1999-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback
Note:
Please contribute updates to this topic on TWiki.org at
TWiki:TWiki.SourceHighlightPlugin
.