1<?php
2/**
3 * CamelCase Plugin: replaces Dokuwiki's own code syntax
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Christopher Smith <chris@jalakai.co.uk>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class  syntax_plugin_camelcase extends DokuWiki_Syntax_Plugin {
18
19
20    /**
21     * return some info
22     */
23    function getInfo(){
24      return array(
25        'author' => 'Christopher Smith',
26        'email'  => 'chris@jalakai.co.uk',
27        'date'   => '2008-08-13',
28        'name'   => 'Camel Case',
29        'desc'   => 'Override default dokuwiki CamelCase syntax',
30        'url'    => 'http://www.dokuwiki.org/plugin:camelcase',
31      );
32    }
33
34    /**
35     * Syntax Type
36     *
37     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
38     */
39    function getType(){
40        return('substition');
41    }
42
43    function connectTo($mode) {
44        $this->Lexer->addSpecialPattern(
45                '\b[A-Z]+[a-z]+[A-Z][A-Za-z]*\b',$mode,'plugin_camelcase'
46            );
47    }
48
49    function getSort() {
50        return 275;   // needs to be lower than 290
51    }
52
53    /**
54     * Handler to prepare matched data for the rendering process
55     */
56    function handle($match, $state, $pos, &$handler){
57
58        preg_match_all('/[A-Z][^A-Z]*/u',$match, $matches);
59        $link = implode('_',$matches[0]);
60        return array($link, $match);
61    }
62
63    /**
64     * Handles the actual output creation.
65     */
66    function render($format, &$renderer, $data) {
67      $renderer->internallink($data[0],$data[1]);
68    }
69
70}
71//Setup VIM: ex: et ts=4 enc=utf-8 :
72