1<?php
2/**
3 * Plugin Label: Allows to mark parts of the wikipage with labels in order to
4 * be qualified for special use in other plugins
5 *
6 * Sytnax: <label [a-zA-Z0-9_]+>...</label>
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Pascal Bihler <bihler@iai.uni-bonn.de>
10 */
11
12// must be run within Dokuwiki
13if(!defined('DOKU_INC')) die();
14
15if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16require_once(DOKU_PLUGIN.'syntax.php');
17
18class syntax_plugin_label extends DokuWiki_Syntax_Plugin {
19
20		var $last_label = array();
21		var $LABEL_PATTERN = "[a-zA-Z0-9_]+";
22
23    /**
24     * return some info
25     */
26    function getInfo(){
27        return array(
28            'author' => 'Pascal Bihler',
29            'email'  => 'bihler@iai.uni-bonn.de',
30            'date'   => '2007-05-14',
31            'name'   => 'Label Plugin',
32            'desc'   => 'Allows to mark parts of the wikipage with labels',
33            'url'    => 'http://wiki.splitbrain.org/plugin:label',
34        );
35    }
36
37    function getType(){ return 'substition'; }
38    function getPType(){ return 'normal'; }
39    function getSort(){ return 100; }
40    function connectTo($mode) {
41						 $this->Lexer->addSpecialPattern('</label>',$mode,'plugin_label');
42						 $this->Lexer->addSpecialPattern('<label\s+' . $this->LABEL_PATTERN . '\s*>',$mode,'plugin_label');
43	  }
44
45
46    /**
47     * Handle the match
48     */
49    function handle($match, $state, $pos, &$handler){
50        switch ($state) {
51          case DOKU_LEXER_SPECIAL :
52					    if (preg_match('/<label\s+(' . $this->LABEL_PATTERN . ')\s*>/',$match,$matches)) {
53								 $labek = $matches[1];
54								 array_push($this->last_label,$label);
55					    	 return array("start", $label);
56						  } else if ($match == "</label>") {
57							   $label = array_pop($this->last_label);
58					    	 return array("end", $label);
59							}
60        }
61        return array();
62    }
63
64    /**
65     * Create output
66     */
67    function render($mode, &$renderer, $data) { //doesn't do much, since label is something internal
68        return true;
69    }
70}
71
72//Setup VIM: ex: et ts=4 enc=utf-8 :