1<?php
2/**
3 * Mediasyntax Plugin: Mediawiki style underline text
4 * <u>..</u> is allowed in mediawiki syntax, see
5 * http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Sanitizer.php?view=markup
6 * This is a part of the mediasyntax plugin for dokuwiki. It handles the <u> tag.
7 * This file must be called underline.php or it will not work.
8 *
9 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
10 * @author     Thorsten Staerk <dev@staerk.de>
11 */
12class syntax_plugin_mediasyntax_underline extends DokuWiki_Syntax_Plugin
13{
14
15  function getType() { return 'protected'; }
16  function getSort() { return 40; }
17
18  function connectTo($mode)
19  {
20    $this->Lexer->addEntryPattern(
21      '<u>',
22      $mode,
23      'plugin_mediasyntax_underline'
24    );
25  }
26
27  function postConnect()
28  {
29    $this->Lexer->addExitPattern(
30      '</u>',
31      'plugin_mediasyntax_underline'
32    );
33  }
34
35  function handle($match, $state, $pos, Doku_Handler $handler)
36  {
37    if ($state == DOKU_LEXER_UNMATCHED) return array($state,$match);
38    if ($state == DOKU_LEXER_ENTER) return array($state,$match);
39    if ($state == DOKU_LEXER_EXIT) return array($state,$match);
40  }
41
42  function render($mode, Doku_Renderer $renderer, $data)
43  // For understanding this see the very valuable code by Christopher Smith on http://www.dokuwiki.org/devel:syntax_plugins
44  // $data is always what the function handle returned!
45  {
46    list($state,$match) = $data;
47    if ($mode == 'xhtml')
48    {
49      if ($state==DOKU_LEXER_ENTER) $renderer->doc .= "<u>";
50      if ($state==DOKU_LEXER_UNMATCHED) $renderer->doc .= $match;
51      if ($state==DOKU_LEXER_EXIT) $renderer->doc .= "</u>";
52    }
53    return false;
54  }
55}
56
57//Setup VIM: ex: et ts=4 enc=utf-8 :
58