1<?php 2/** 3 * Folded text Plugin, header component: 4 * Render headers included in folded blocks. 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author LarsDW223 8 */ 9 10/** 11 * This class handles header syntax inside folded blocks. 12 * A found header syntax will be rendered as an html header element but 13 * is not a DokuWiki header (no section edit, do not appear in toc). 14 */ 15class syntax_plugin_folded_header extends DokuWiki_Syntax_Plugin { 16 17 function getType(){ return 'formatting'; } 18 function getPType() { return 'block'; } 19 function getSort(){ return 50; } 20 function connectTo($mode) { 21 if ($mode != 'plugin_folded_div') return; 22 23 // Copied from parser: we're not picky about the closing ones, two are enough 24 $this->Lexer->addSpecialPattern( 25 '[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)', 26 $mode, 27 'plugin_folded_header' 28 ); 29 } 30 31 /** 32 * Handle the match 33 */ 34 function handle($match, $state, $pos, Doku_Handler $handler){ 35 // Copied from parser: get level and title 36 $title = trim($match); 37 $level = 7 - strspn($title,'='); 38 if($level < 1) $level = 1; 39 $title = trim($title,'='); 40 $title = trim($title); 41 return array($title,$level,$pos); 42 } 43 44 /** 45 * Create output 46 */ 47 function render($mode, Doku_Renderer $renderer, $data) { 48 if($mode != 'xhtml') return; 49 50 list($text,$level,$pos) = $data; 51 52 // Write the header 53 $renderer->doc .= DOKU_LF.'<h'.$level.'>'; 54 $renderer->cdata($text); 55 $renderer->doc .= "</h$level>".DOKU_LF; 56 return true; 57 } 58} 59