This is an old revision of the document!
Table of Contents
Code Replacement Plugin
Compatible with DokuWiki
2005-09-22 and later
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Similar to code, code2, code3, highlightjs, jquery-syntax, syntaxhighlighter, syntaxhighlighter2, syntaxhighlighter3, syntaxhighlighter4, wpre, xssnipper, xterm
This plugin replaces the current DokuWiki handlers for <code> </code>
& <file> </file>
markup. It adds ability to recognize and render a title above the code box.
This plugin was inspired by 477 and my own curiosity to see if it was possible to override DokuWiki's native syntax handling.
There is another Code Plugin which adds line numbers, console mode and can highlight diff output.
See the plugin in action here (or below)
Syntax
<code lang | title> some code </code>
<file | title> some text </file>
lang
The lang
parameter causes the syntax highlighting according to the language you specify
Supported parameters (fileextensions given if differ from lang):
- this list is incomplete, please add any supported language thats not listed
A full list of supported languages can be found here.
- actionscript
as
- c
- cpp
- csharp
- css
- html
- ini
- java
- javascript
js
(including JSON) - nsis
- php
- plsql
- python
py
- sql
- xml
- bash
- delphi
- asp.net asp
- coldfusion cfm
title
Adding a title
will add a small flag ontop of the codebox to enable the direct downloading of the sourcecode
If no title
is given the plugin will render the <code>
or <file>
markup identically to the native DokuWiki handler.
Installation
Plugin sources: zip format (4k), tar.gz format (2k) | darcs (requires darcs plugin)
Download the source to your plugin folder, lib/plugins
and extract its contents. That will create a new plugin folder, lib/plugins/code
, and install the plugin.
The folder will contain:
style.css styles for the new boxes and titles syntax/ syntax plugin folder syntax/code.php plugin script for <code> syntax/file.php plugin script for <file>
The plugin is now installed.
Details
The plugin consists of three files, two (almost identical) syntax plugins files, syntax/code.php & syntax/file.php and some CSS styles, style.css.
syntax/code.php
- code.php
<?php /** * Code Plugin: replaces DokuWiki's own code syntax * * Syntax: <code lang |title> * lang (optional) programming language name, is passed to geshi for code highlighting * if not provided, the plugin will attempt to derive a value from the file name * (refer $extensions in render() method) * title (optional) all text after '|' will be rendered above the main code text with a * different style. * * if no title is provided will render as native DokuWiki code syntax mode, e.g. * <pre class='code {lang}'> ... </pre> * * if title is provide will render as follows * <div class='source'> * <p>{title}</p> * <pre class='code {lang}'> ... </pre> * </div> * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@jalakai.co.uk> */ if(!defined('DOKU_INC')) die(); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_code_code extends DokuWiki_Syntax_Plugin { var $syntax = ""; //Setup VIM: ex: et ts=4 enc=utf-8 :
syntax/file.php
- file.php
<?php /** * File Plugin: replaces DokuWiki's own file syntax * * Syntax: <file |title> * title (optional) all text after '|' will be rendered above the main code text with a * different style. * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@jalakai.co.uk> */ if(!defined('DOKU_INC')) die(); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_code_file extends DokuWiki_Syntax_Plugin { //Setup VIM: ex: et ts=4 enc=utf-8 :