DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:linkext

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
plugin:linkext [2007-02-12 06:26] ShTiRLiCplugin:linkext [2009-01-02 23:39] 70.103.232.219
Line 1: Line 1:
 +====== 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       : linking, links, MediaWiki
 +----
 +
 +This plugin concatenates part of word after internal link and its body (like in MediaWiki) so when you write <nowiki>[[test]]ing</nowiki> 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.
 +
 +<code php>
 +<?php
 +/**
 + * Plugin Linkext: merges links body and its end.
 + *
 + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 + * @author     Serge Shpikin <shtirlic@shtirlic.com>
 + */
 +
 +// 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;
 +    }
 +}
 +</code>
 +
 +====== Comments ======
 +
 +> The problem is that if i write <nowiki>[[test]]ing</nowiki>, alone is colored the word **test** and **ing** is not colored. 
plugin/linkext.txt · Last modified: 2009-10-06 10:01 by laynee

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki