This section is just to provide some intro for new plugin developers of DokuWiki. It will provide short explanation to introduce into simple syntax development.
We tried to provide balanced articles reduced to the most important facts instead explaining the whole world. We spiced the practical things, which can be easily followed up, with very few and short notes where we thought it is indispensable to understand some dependencies. Those will deliver at least a basic idea and some key-words for further self-made search attempts within the DokuWiki.org or Forum for further explanations.
Please do not hesitate to Contact us in the event of questions, suggestions and comments.
Enjoy coding
Taggic
The following section delivers a simple plugin what just output the given parameter. To see that it is really done by the plugin it adds the 'MOO' text around. It is just to provide you an introducing overview without stepping into much details, therefore please read the comments within the php-code section of this chapter.
-
syntax.php
-
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/******************************************************************************
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_xsstuff extends DokuWiki_Syntax_Plugin
{
/******************************************************************************/
/* return some info - for compatibility (DW Release Lemmings and before)
* plugin.info.txt needed in any case !
*/
function getInfo(){
return confToHash(dirname(__FILE__).'/plugin.info.txt');
}
function getType(){ return 'substition';} // Returns the type of syntax this plugin defines
function getPType(){ return 'block';} // Defines how this syntax is handled regarding paragraphs
function getSort(){ return 999;} // Returns a number used to determine in which order modes are added
/******************************************************************************/
/* Connect pattern to lexer
*/
function connectTo($mode){
$this->Lexer->addSpecialPattern('\{\[^}]*\>\}',$mode,'plugin_xsstuff');
}
/******************************************************************************/
/* Handle the match
*/
function handle($match, $state, $pos, &$handler) {
global $ID;
// lets assume your syntax line looking as follows:
// {alpha,bravo,charly>}
$match = substr($match,strlen('{'),-2); //strip markup from start and end = 'alpha,bravo,charly'
//handle params: load params into an array
// the following will split the parameter string into an array of parameter
$params = explode(',',$match);
return $params;
}
/******************************************************************************/
/* Create output
*/
function render($mode, &$renderer, $data) {
// chain params comma separated = alpha,bravo,charly
$params = implode(',',$data);
$ret ='MOO->| ' .$params. ' |<-MOO';
// Render: output of syntax parameter as text
$renderer->doc .= $ret;
}
}
<?php
/**
* xsstuff Plugin: Plugin Dev Jumpstart - skeleton + simple plugin function
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Taggic <taggic@t-online.de>
*/
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC
.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/******************************************************************************
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_xsstuff extends DokuWiki_Syntax_Plugin
{
/******************************************************************************/
/* return some info - for compatibility (DW Release Lemmings and before)
* plugin.info.txt needed in any case !
*/
function getInfo(){
return confToHash
(dirname(__FILE__).'/plugin.info.txt');
}
function getType(){ return 'substition';} // Returns the type of syntax this plugin defines
function getPType(){ return 'block';} // Defines how this syntax is handled regarding paragraphs
function getSort(){ return 999;} // Returns a number used to determine in which order modes are added
/******************************************************************************/
/* Connect pattern to lexer
*/
function connectTo($mode){
$this->Lexer->addSpecialPattern('\{\<xsstuff>[^}]*\>\}',$mode,'plugin_xsstuff');
}
/******************************************************************************/
/* Handle the match
*/
function handle($match, $state, $pos, &$handler) {
global $ID;
// lets assume your syntax line looking as follows:
// {<xsstuff>alpha,bravo,charly>}
$match = substr($match,strlen('{<xsstuff>'),-2); //strip markup from start and end = 'alpha,bravo,charly'
//handle params: load params into an array
// the following will split the parameter string into an array of parameter
return $params;
}
/******************************************************************************/
/* Create output
*/
function render($mode, &$renderer, $data) {
// chain params comma separated = alpha,bravo,charly
$ret ='MOO->| ' .$params. ' |<-MOO';
// Render: output of syntax parameter as text
$renderer->doc .= $ret;
}
}
{<xsstuff>alpha,bravo,charly>}
MOO->| alpha,bravo,charly |<-MOO
To get the complete plugin please download: xsstuff.zip
See the following example regarding direct html and styling output, it is simple add. The example shows that you can also output self-made html-code. Just modify the render function of your xsStuff plugin accordingly (or download the zip below). The page syntax keeps unchanged. You may store the style into a “style.css” file within your plugin folder. Do not forget to add a related class to the html code of syntax file if you use style.css.
-
syntax.php
- /******************************************************************************/
/* Create output
*/
function render($mode, &$renderer, $data) {
// let's loop through the parameter and put color and text style to each of them
$color = array('red','green','blue');
$txt_style = array('bold','normal','bolder');
$s=0;
foreach($data as $bit) {
$output .= ''.$bit.'
';
$s++;
if($s>2) $s=0;
}
// Render: output of syntax parameter as colored, styled text, one below the other
$renderer->doc .= $output;
}
/******************************************************************************/
/* Create output
*/
function render($mode, &$renderer, $data) {
// let's loop through the parameter and put color and text style to each of them
$color = array('red','green','blue');
$txt_style = array('bold','normal','bolder');
$s=0;
foreach($data as $bit) {
$output .= '<span style="color:'.$color[$s].'; font-weight:'.$txt_style[$s].';">'.$bit.'</span><br />';
$s++;
if($s>2) $s=0;
}
// Render: output of syntax parameter as colored, styled text, one below the other
$renderer->doc .= $output;
}
alpha
bravo
charly
To get the complete plugin please download: xmstuff.zip