1<?php
2/**
3 * DokuWiki Plugin Abbr: abbr tag for abbreviation in Wiki text
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Satoshi Sahara <sahara.satoshi@gmail.com>
7 *
8 * SYNTAX:
9 *       <abbr title="description">TARGET</abbr>
10 *
11 * OUTPUT:
12 *       <abbr title="description">TARGET</abbr>
13 */
14
15if(!defined('DOKU_INC')) die();
16
17class syntax_plugin_abbr_htmltag extends DokuWiki_Syntax_Plugin {
18
19    protected $entry_pattern    = '<abbr\b(?:\s+title=.*?)>(?=.*?</abbr>)';
20    protected $exit_pattern     = '</abbr>';
21
22    public function getType() { return 'formatting'; }
23    public function getSort() { return 305; }
24
25    public function connectTo($mode) {
26        $this->Lexer->addEntryPattern($this->entry_pattern,$mode,substr(get_class($this), 7));
27    }
28    public function postConnect() {
29        $this->Lexer->addExitPattern($this->exit_pattern,substr(get_class($this), 7));
30    }
31
32   /**
33    * Handle the match
34    */
35    public function handle($match, $state, $pos, Doku_Handler $handler) {
36
37        switch ($state) {
38            case DOKU_LEXER_ENTER :
39            case DOKU_LEXER_UNMATCHED :
40            case DOKU_LEXER_EXIT :
41                return array($state, $match);
42                break;
43        }
44        return false;
45    }
46
47   /**
48    * Create output
49    */
50    public function render($format, Doku_Renderer $renderer, $data) {
51
52        if($format == 'xhtml') {
53            list($state, $match) = $data;
54            $match = $data[1];
55
56            switch ($state) {
57                case DOKU_LEXER_ENTER :
58                    $renderer->doc .= $match;
59                    break;
60            //  case DOKU_LEXER_MATCHED :
61            //      break;
62                case DOKU_LEXER_UNMATCHED :
63                    $renderer->doc .= $renderer->_xmlEntities($match);
64                    break;
65                case DOKU_LEXER_EXIT :
66                    $renderer->doc .= $match;
67                    break;
68            //  case DOKU_LEXER_SPECIAL :
69            //      break;
70            }
71            return true;
72        }
73        return false;
74    }
75}
76