1<?php
2/**
3 * Plugin Acronym: Allows to use the acronym tag in HTML
4 *
5 * Syntax: <acronym title="my explanation">
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Thorsten Staerk <dev@staerk.de>
9 */
10
11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class syntax_plugin_acronym extends DokuWiki_Syntax_Plugin
20{
21
22    function getInfo()
23    {
24        return array
25        (
26            'author' => 'Thorsten Staerk',
27            'email'  => 'dev@staerk.de',
28            'date'   => '2011-06-30',
29            'name'   => 'Acronym Plugin',
30            'desc'   => 'allows you to use the acronym html tag',
31            'url'    => 'http://www.staerk.de/thorsten/Acronym',
32        );
33    }
34
35   /**
36    * Get the type of syntax this plugin defines.
37    *
38    * @param none
39    * @return String <tt>'substition'</tt> (i.e. 'substitution').
40    * @public
41    * @static
42    */
43    function getType()
44    {
45        return 'formatting';
46    }
47
48   /**
49    * Where to sort in?
50    *
51    * @param none
52    * @return Integer <tt>6</tt>.
53    * @public
54    * @static
55    */
56    function getSort()
57    {
58        return 1;
59    }
60
61
62   /**
63    * Connect lookup pattern to lexer.
64    *
65    * @param $aMode String The desired rendermode.
66    * @return none
67    * @public
68    * @see render()
69    */
70    function connectTo($mode)
71    {
72        $this->Lexer->addEntryPattern('<acronym title=.*?>(?=.*?</acronym>)',$mode,'plugin_acronym');
73    }
74
75    function postConnect()
76    {
77        $this->Lexer->addExitPattern('</acronym>','plugin_acronym');
78    }
79
80
81   /**
82    * Handler to prepare matched data for the rendering process.
83    *
84    * <p>
85    * The <tt>$aState</tt> parameter gives the type of pattern
86    * which triggered the call to this method:
87    * </p>
88    * <dl>
89    * <dt>DOKU_LEXER_ENTER</dt>
90    * <dd>a pattern set by <tt>addEntryPattern()</tt></dd>
91    * <dt>DOKU_LEXER_MATCHED</dt>
92    * <dd>a pattern set by <tt>addPattern()</tt></dd>
93    * <dt>DOKU_LEXER_EXIT</dt>
94    * <dd> a pattern set by <tt>addExitPattern()</tt></dd>
95    * <dt>DOKU_LEXER_SPECIAL</dt>
96    * <dd>a pattern set by <tt>addSpecialPattern()</tt></dd>
97    * <dt>DOKU_LEXER_UNMATCHED</dt>
98    * <dd>ordinary text encountered within the plugin's syntax mode
99    * which doesn't match any pattern.</dd>
100    * </dl>
101    * @param $aMatch String The text matched by the patterns.
102    * @param $aState Integer The lexer state for the match.
103    * @param $aPos Integer The character position of the matched text.
104    * @param $aHandler Object Reference to the Doku_Handler object.
105    * @return Integer The current lexer state for the match.
106    * @public
107    * @see render()
108    * @static
109    */
110    function handle($match, $state, $pos, Doku_Handler $handler)
111    {
112        switch ($state)
113        {
114            case DOKU_LEXER_ENTER :
115                return array($state, $match);
116            case DOKU_LEXER_MATCHED :
117                //break;
118            case DOKU_LEXER_UNMATCHED :
119                return array($state, $match);
120            case DOKU_LEXER_EXIT :
121                return array($state, '');
122            case DOKU_LEXER_SPECIAL :
123                //break;
124        }
125        return false;
126    }
127
128   /**
129    * Handle the actual output creation.
130    *
131    * <p>
132    * The method checks for the given <tt>$aFormat</tt> and returns
133    * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt>
134    * contains a reference to the renderer object which is currently
135    * handling the rendering. The contents of <tt>$aData</tt> is the
136    * return value of the <tt>handle()</tt> method.
137    * </p>
138    * @param $aFormat String The output format to generate.
139    * @param $aRenderer Object A reference to the renderer object.
140    * @param $aData Array The data created by the <tt>handle()</tt>
141    * method.
142    * @return Boolean <tt>TRUE</tt> if rendered successfully, or
143    * <tt>FALSE</tt> otherwise.
144    * @public
145    * @see handle()
146    */
147    function render($mode, Doku_Renderer $renderer, $data)
148    {
149        if($mode == 'xhtml')
150        {
151            list($state,$match) = $data;
152            $match=$data[1];
153            switch ($state)
154            {
155                case DOKU_LEXER_ENTER :
156                    $renderer->doc .= "$match";
157                case DOKU_LEXER_UNMATCHED :
158                    $renderer->doc .= "$match";
159                case DOKU_LEXER_EXIT :
160                    $renderer->doc .= "</acronym>";
161            }
162            return true;
163        }
164        return false;
165    }
166}
167
168//Setup VIM: ex: et ts=4 enc=utf-8 :
169?>
170
171