1<?php
2/**
3 * Creole Plugin, linebreak component: Inserts a line break
4 * based on Linebreak Plugin http://wiki.splitbrain.org/plugin:linebreak
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Christopher Smith <chris@jalakai.co.uk>
8 * @author     Esther Brunner <wikidesign@gmail.com>
9 */
10
11/**
12 * All DokuWiki plugins to extend the parser/rendering mechanism
13 * need to inherit from this class
14 */
15class syntax_plugin_creole_linebreak extends DokuWiki_Syntax_Plugin {
16
17    function getType() { return 'substition'; }
18    function getSort() { return 100; }
19
20    function connectTo($mode) {
21        $this->Lexer->addSpecialPattern(
22                '(?<!^|\n)\n(?!\n|>)',
23                $mode,
24                'plugin_creole_linebreak'
25                );
26    }
27
28    function handle($match, $state, $pos, Doku_Handler $handler) {
29
30        if ($match == "\n") return true;
31        return false;
32    }
33
34    function render($mode, Doku_Renderer $renderer, $data) {
35        if($mode == 'xhtml') {
36            if ($data) {
37                if ( $this->getConf('linebreak') == 'Linebreak' ) {
38                    $renderer->doc .= "<br />";
39                } else {
40                    $renderer->doc .= " ";
41                }
42            }
43            return true;
44        }
45        return false;
46    }
47}
48// vim:ts=4:sw=4:et:enc=utf-8:
49