This is a very small and simple plugin to place defined snippets of a file onto your page or just output a code snipped with line numbering.
This plugin delivers following:
code snippets directly from files or just copy-paste a code block
code line numbering
direct link of commands to online descriptions (e.g. php.net)
downloadable code blocks
css supported box style
adds code buttons to the Editor Toolbar
The following syntax does apply: {(xssnipper>,[start line],[code language] [code block file] [slider] ,[code])} where [code language] [code block file] [slider] are optional and [code] is the snipped you want to show.
Remark: click on the red arrow to show/hide the code block
-
test
-
// 1. check if $xssnipper['filepath'] exist, else error message
if(!file_exists($xssnipper['filepath'])) {
msg('file '.$xssnipper['filepath'].' not found',-1);
return false;
}
// 1. check if $xssnipper['filepath'] exist, else error message
msg('file '.$xssnipper['filepath'].' not found',-1);
return false;
}
The following Syntax was used for upper example:
{(xssnipper>,1,php test slide,
// 1. check if $xssnipper['filepath'] exist, else error message
if(!file_exists($xssnipper['filepath'])) {
msg('file '.$xssnipper['filepath'].' not found',-1);
return false;
}
)}
The following syntax does apply: {(xssnipper>[PATH],[from line],[to line],[code language] [code block file] [slider])}.
Parameter | Necessity | Meaning |
[PATH] | mandatory | specifies the file where content to be picked up |
[from line] | optional | defines the first line to be displayed, if empty it will be set to zero; if further parameter will be given at least the colon separator to be written |
[to line] | optional | defines the last line to be displayed, if empty it will be set to end of file; if further parameter will be given at least the colon separator to be written |
[code language] | optional | tells code block/GeSHi what language file to be used for colouring, file extension of the [path] parameter will be used if empty |
[code block file] | optional | enables the download code blocks feature and specifies the file name, if empty no downloadable code block provided (file name must not contain space character !) |
[slider] | optional | enables the view/hide (slide) function of the code block. Any value will switch on this function (e.g. 1 or on or slide). If set the code will be hidden initially. |
Simply place the following syntax into the page mark-up:
{(xssnipper>./lib/plugins/xssnipper/plugin.info.txt,1,15,txt test.txt)}
This should deliver lines 1 to 15 as plain text (downloadable as test.txt file) from the current plugin info file as follows:
-
plugin.info.txt
- # PLUGIN INFO - DO NOT EDIT!
base xssnipper
author Taggic
email taggic@t-online.de
date 2012-06-22
name xssnipper
desc provides syntax plugin to retrieve code snippeds from files
url http://www.dokuwiki.org/plugin:xssnipper
# PLUGIN INFO - DO NOT EDIT!
base xssnipper
author Taggic
email taggic@t-online.de
date 2012-06-22
name xssnipper
desc provides syntax plugin to retrieve code snippeds from files
url http://www.dokuwiki.org/plugin:xssnipper
You see the output stops before line 15 was reached beacuse end of file reached.
The snippets are displayed with Syntax Highlighting of DokuWiki GeSHi implementation. The output can be styled via a css-file.
The filename will be taken from the path you passed else you provided another filename after the [code language] parameter.
The following example visualize it for better understanding:
{(xssnipper>./lib/plugins/xssnipper/syntax.php,85,104,php)}
-
syntax.php
- $xssnipper['filepath'] = $params[0];
$xssnipper['from'] = $params[1];
$xssnipper['until'] = $params[2];
$alpha = explode(' ',$params[3]);
$xssnipper['type'] = $alpha[0];
$xssnipper['file'] = $alpha[1];
$xssnipper['block'] = $alpha[2];
}
return $xssnipper;
}
/******************************************************************************/
/* render output
* @author Taggic
*/
function render($mode, &$renderer, $xssnipper) {
global $ID;
if(!$xssnipper['type']) $xssnipper['type']='txt';
if($this->_codeblock<1) $this->_codeblock=1;
$xssnipper['filepath'] = $params[0];
$xssnipper['from'] = $params[1];
$xssnipper['until'] = $params[2];
$xssnipper['type'] = $alpha[0];
$xssnipper['file'] = $alpha[1];
$xssnipper['block'] = $alpha[2];
}
return $xssnipper;
}
/******************************************************************************/
/* render output
* @author Taggic <taggic@t-online.de>
*/
function render($mode, &$renderer, $xssnipper) {
global $ID;
if(!$xssnipper['type']) $xssnipper['type']='txt';
if($this->_codeblock<1) $this->_codeblock=1;
The plugin will show all codelines from defined start parameter until end of file if you leave the [to line] parameter empty.
Install the plugin using the Plugin Manager and the download URL above, which points to latest version of the plugin.
Refer to Plugins on how to install plugins manually.
Or just download and extract it as folder “xssnipper” into your “\lib\plugins” directory.
External requirements:
Date | Changes |
2012-06-22 | - slide feature to show/hide the code details |
2012-01-18 | - code line numbering
- stylesheet support
- direct use of GeSHi syntax highlighting
- optional parameter to shorten syntax line
- BugFix: start/end lines of snippets corrected
downloadable code blocks just brocken bug fixed |
2011-12-21 | - Initial release |
The plugin was tested with DW 2011-05-25 “Rincewind” and also with related on the Stick version.
Our standard browser is Internet Explorer 9 due to majority of customers using it.
However, that is no guarantee that it works for all environmental configuration.
Please use only the DokuWiki Forum for discussion and xsSnipper - IssueTracker to raise issues.
The plugin development is still ongoing. There might be something be corrected, to implement and to improve.