-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render header syntax as simple html headers (not as full DokuWiki hea…
…ders). This means that headlines in a folded block will not appear in the ToC and they will not have an own section edit button.
- Loading branch information
1 parent
3ccc2e1
commit 9f74e0e
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |