1<?php
2/*
3 * Setext style headers:
4 *  Header
5 *  ======
6 */
7
8if (!defined('DOKU_INC')) die();
9if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
10require_once (DOKU_PLUGIN . 'syntax.php');
11
12class syntax_plugin_markdowku_headersetext extends DokuWiki_Syntax_Plugin {
13
14    function getType()  { return 'baseonly'; }
15    function getPType() { return 'block'; }
16    function getSort()  { return 49; }
17    function getAllowedTypes() {
18        return array('formatting', 'substition', 'disabled', 'protected');
19    }
20
21    function connectTo($mode) {
22        $this->Lexer->addSpecialPattern(
23            '\n[^\n]+[ \t]*\n=+[ \t]*(?=\n)',
24            'base',
25            'plugin_markdowku_headersetext');
26
27        $this->Lexer->addSpecialPattern(
28            '\n[^\n]+[ \t]*\n-+[ \t]*(?=\n)',
29            'base',
30            'plugin_markdowku_headersetext');
31    }
32
33    function handle($match, $state, $pos, Doku_Handler $handler) {
34        $title = preg_replace('/^\n(.+?)[ \t]*\n.*/', '\1', $match);
35        $title = trim($title);
36        if (preg_match('/^\n(.+?)[ \t]*\n=/', $match))
37            $level = 1;
38        if (preg_match('/^\n(.+?)[ \t]*\n-/', $match))
39            $level = 2;
40
41        if ($handler->getStatus('section'))
42            $handler->_addCall('section_close', array(), $pos);
43        $handler->setStatus('section_edit_start', $pos);
44        $handler->setStatus('section_edit_level', $level);
45        $handler->setStatus('section_edit_title', $title);
46        $handler->_addCall('header', array($title, $level, $pos), $pos);
47        $handler->_addCall('section_open', array($level), $pos);
48        $handler->setStatus('section', true);
49        return true;
50    }
51
52    function render($mode, Doku_Renderer $renderer, $data) {
53        return true;
54    }
55}
56//Setup VIM: ex: et ts=4 enc=utf-8 :
57