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