1<?php
2/**
3 * Mediasyntax Plugin, header component: Mediawiki style headers
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Esther Brunner <wikidesign@gmail.com>
7 */
8class syntax_plugin_mediasyntax_header extends DokuWiki_Syntax_Plugin
9{
10
11    function getType()  { return 'container'; }
12    function getPType() { return 'block'; }
13    function getSort()  { return 49; }
14
15    function getAllowedTypes()
16    {
17        return array('formatting', 'substition', 'disabled', 'protected');
18    }
19
20    function preConnect()
21    {
22        $this->Lexer->addSpecialPattern(
23            '(?m)^[ \t]*=+[^\n]+=+[ \t]*$',
24            'base',
25            'plugin_mediasyntax_header'
26        );
27    }
28
29    function handle($match, $state, $pos, Doku_Handler $handler)
30    {
31        global $conf;
32
33        // get level and title
34        $title = trim($match);
35        $level = strspn($title, '=');
36        if ($level < 1) $level = 1;
37        elseif ($level > 5) $level = 5;
38        $title = trim($title, '=');
39        $title = trim($title);
40
41        if ($handler->getStatus('section')) $handler->addCall('section_close', array(), $pos);
42
43        if ($level <= $conf['maxseclevel'])
44        {
45            $handler->setStatus('section_edit_start', $pos);
46            $handler->setStatus('section_edit_level', $level);
47            $handler->setStatus('section_edit_title', $title);
48        }
49
50        $handler->addCall('header', array($title, $level, $pos), $pos);
51
52        $handler->addCall('section_open', array($level), $pos);
53        $handler->setStatus('section', true);
54        return true;
55    }
56
57    function render($mode, Doku_Renderer $renderer, $data)
58    {
59        return true;
60    }
61}
62
63//Setup VIM: ex: et ts=4 enc=utf-8 :
64