1<?php
2/**
3 * DokuWiki Plugin headernofloat (Syntax Component)
4 *
5 *
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author  lisps
8 */
9
10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14class syntax_plugin_headernofloat extends DokuWiki_Syntax_Plugin {
15
16		var $levels = array( '######'=>1,
17                         '#####'=>2,
18                         '####'=>3,
19                         '###'=>4,
20                         '##'=>5);
21
22		function getPType() {return 'normal';	}
23        // header specific
24        function getType() { return 'substition'; }
25
26        // headings shouldn't be parsed..
27        function accepts($mode) { return false; }
28
29        function connectTo( $mode ) {
30                $this->Lexer->addSpecialPattern( '^[ \t]*#{2,6}[^\n]+#{2,6}[ \t]*(?=\n)', $mode, 'plugin_headernofloat' );
31        }
32
33        // Doku_Parser_Mode 60
34        // header (numbered headers) 45
35        function getSort() { return 59; }
36
37        function handle( $match, $state, $pos, &$handler )
38        {
39			// get level and title
40			$title = trim($match);
41			$level = 7 - strspn($title,'#');
42			if($level < 1) $level = 1;
43			$title = trim($title,'#');
44			$title = trim($title);
45
46			$opts["sectionstatus"] = false;
47			if ($handler->status['section']) {
48				$opts["sectionstatus"] = true;
49
50			}
51			$handler->status['section'] = true;
52
53			$opts["text"] = $title;
54			$opts["level"] = $level;
55			$opts["pos"] = $pos;
56			return $opts;
57        }
58
59        function render( $mode, &$renderer, $data )
60        {
61			$title = $text = $data["text"];
62			$level= $data["level"];
63			$pos = $data["pos"];
64			$sectionstatus = $data["sectionstatus"];
65			if($mode == 'metadata')return false;
66			if($sectionstatus == true) $renderer->section_close();
67
68			if($mode=="xhtml") {
69				$renderer->doc .= ("<div class='nofloat'>");
70				$renderer->header($title, $level, $pos);
71				$renderer->doc .=("</div>");
72			} else if($mode=='odt'){
73				$renderer->header($title, $level, $pos);
74			}
75			else {
76				$renderer->doc .=$renderer->_xmlEntities($title);
77			}
78			$renderer->section_open($level);
79
80			return true;
81        }
82
83}
84