====== Summary ======
---- plugin ----
description: This plugin concatenates part of word after internal link and its body.
author : Serge Shpikin
email : ShTiRLiC@shtirlic.com
type : syntax
lastupdate : 2007-02-12
compatible :
depends :
conflicts :
similar :
tags : links, MediaWiki
----
This plugin concatenates part of word after internal link and its body (like in MediaWiki) so when you write [[test]]ing this link will be shown as 'testing' and point to 'test'.
This is my first plugin so it may work bad but I hope it'll be useful.
You may download it from [[http://shtirlic.com/wiki/_media/plugins:linkext.zip]] or just copy the source code.
*/
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
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_linkext extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'Serge Shpikin',
'email' => 'ShTiRLiC@shtirlic.com',
'date' => '2007-02-12',
'name' => 'Link Extension Plugin',
'desc' => 'Concatenates links ending and body (a-la MediaWiki) which is useful for Cyrillic languages (like Russian, Ukrainian etc.). Links like [[test]]ing will be shown as "testing" and point to "test"',
'url' => 'http://shtirlic.com',
);
}
function getType()
{
return 'substition';
}
function getSort()
{
return 51;
}
function connectTo($mode)
{
$this->Lexer->addSpecialPattern('\[\[[^\s\|]+?\]\][a-zA-Zа-яА-Я]+?\s',$mode,'plugin_linkext');
}
function handle($match, $state, $pos, &$handler)
{
if ($state == DOKU_LEXER_SPECIAL)
{
preg_match('/\[\[(.+?)\]\](.+?)\s/', $match, $data);
return array($state, $data);
}
else
return array($match, $state, $pos);
}
function render($mode, &$renderer, $data)
{
if($mode == 'xhtml')
{
list($state, $match) = $data;
$spos = strrpos($match[1], ':');
if (!is_bool($spos))
$caption = substr($match[1], $spos + 1, strlen($match[1]) - $spos);
else
$caption = $match[1];
if ($state == DOKU_LEXER_SPECIAL)
{
$renderer->internallink($match[1], $caption.$match[2]);
$renderer->doc .= ' ';
}
else
{
$renderer->doc .= $match;
}
return true;
}
return false;
}
}
====== Comments ======
> The problem is that if i write [[test]]ing, alone is colored the word **test** and **ing** is not colored.