xsSnipper Plugin

PluginxsSnipper
Description Exctract a snippet of a file and publish it on your page.
Type syntax
Author Taggic
Last update 2012-06-22
DW compatible 2011-05-25 (Rincewind), 2011-11-10 (Angua)
Depends none
Conflicts none
Similar none
Download https://github.com/Taggic/xsSnipper/archives/master
Issues fcon - xsSnipper issues

Vote for this plugin

xsSnipper
(79) (92)


Feature Overview

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

Syntax

Case 1: Standard code snipped

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

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;
   }
)}

Case 2: Code snipped from a file

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

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;
  1.           $xssnipper['filepath']    = $params[0];
  2.           $xssnipper['from']        = $params[1];
  3.           $xssnipper['until']       = $params[2];
  4.           $alpha                    = explode(' ',$params[3]);
  5.           $xssnipper['type']        = $alpha[0];
  6.           $xssnipper['file']        = $alpha[1];
  7.           $xssnipper['block']       = $alpha[2];
  8.         }        
  9.         return $xssnipper;
  10.      }
  11. /******************************************************************************/
  12. /* render output
  13. * @author Taggic <taggic@t-online.de>
  14. */  
  15.     function render($mode, &$renderer, $xssnipper) {
  16.         global $ID;
  17.         if(!$xssnipper['type'])  $xssnipper['type']='txt';
  18.         if($this->_codeblock<1)  $this->_codeblock=1;
  19.  
  20.  

The plugin will show all codelines from defined start parameter until end of file if you leave the [to line] parameter empty.

Installation

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:

  • none

Changes

Configuration

  • none

Major Changes Log

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

Version/Requirements

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.

Potential for improvements

Please use the Contact us form or the xsSnipper - IssueTracker to send us your wish or Feature Request.

Discussion

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.

FAQ

xssnipper/xssnipper.txt · Last modified: 2014/10/14 17:55 by taggic

This Wiki is hosted and ruled by Policies of Frister Consultancy Services.
By using this wiki you accept these rules. -> Impressum