Skip to content

Commit

Permalink
Merge pull request #38 from LarsGit223/master
Browse files Browse the repository at this point in the history
Render header syntax as simple html headers (not as full DokuWiki headers).
  • Loading branch information
LarsGit223 authored May 30, 2017
2 parents 3ccc2e1 + 9f74e0e commit deeb6cb
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions syntax/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Folded text Plugin, header component:
* Render headers included in folded blocks.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author LarsDW223
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

/**
* This class handles header syntax inside folded blocks.
* A found header syntax will be rendered as an html header element but
* is not a DokuWiki header (no section edit, do not appear in toc).
*/
class syntax_plugin_folded_header extends DokuWiki_Syntax_Plugin {

function getType(){ return 'formatting'; }
function getPType() { return 'block'; }
function getSort(){ return 50; }
function connectTo($mode) {
if ($mode != 'plugin_folded_div') return;

// Copied from parser: we're not picky about the closing ones, two are enough
$this->Lexer->addSpecialPattern(
'[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)',
$mode,
'plugin_folded_header'
);
}

/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
// Copied from parser: get level and title
$title = trim($match);
$level = 7 - strspn($title,'=');
if($level < 1) $level = 1;
$title = trim($title,'=');
$title = trim($title);
return array($title,$level,$pos);
}

/**
* Create output
*/
function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return;

list($text,$level,$pos) = $data;

// Write the header
$renderer->doc .= DOKU_LF.'<h'.$level.'>';
$renderer->cdata($text);
$renderer->doc .= "</h$level>".DOKU_LF;
return true;
}
}

0 comments on commit deeb6cb

Please sign in to comment.