Commit c35617cd authored by Anna Dabrowska's avatar Anna Dabrowska

Special handling of headlines

Solution from wrap plugin
parent 2fe43ad9
......@@ -55,11 +55,13 @@ class syntax_plugin_ifauthex extends DokuWiki_Syntax_Plugin
public function postConnect()
{
$this->Lexer->addExitPattern('</ifauth>', 'plugin_ifauthex');
$this->Lexer->addPattern('[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)', 'plugin_ifauthex');
}
/** @inheritDoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
global $conf;
switch ($state) {
case DOKU_LEXER_ENTER:
$matches = null;
......@@ -72,6 +74,22 @@ class syntax_plugin_ifauthex extends DokuWiki_Syntax_Plugin
return array($state, $matches[count($matches) - 1]);
}
return array($state, null);
case DOKU_LEXER_MATCHED:
// source of the following solution: plugin wrap
// we have a == header ==, use the core header() renderer
// (copied from core header() in inc/parser/handler.php)
$title = trim($match);
$level = 7 - strspn($title,'=');
if($level < 1) $level = 1;
$title = trim($title,'=');
$title = trim($title);
$handler->_addCall('header',array($title,$level,$pos), $pos);
// close the section edit the header could open
if ($title && $level <= $conf['maxseclevel']) {
$handler->addPluginCall('ifauthex_closesection', array(), DOKU_LEXER_SPECIAL, $pos, '');
}
break;
case DOKU_LEXER_UNMATCHED:
return array($state, $match);
case DOKU_LEXER_EXIT:
......
<?php
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/**
* Copy of syntax_plugin_wrap_closesection
* Used for special handling of headers
*/
class syntax_plugin_ifauthex_closesection extends DokuWiki_Syntax_Plugin {
function getType() { return 'substition';}
function getPType() { return 'block';}
function getSort() { return 195; }
/**
* Dummy handler, this syntax part has no syntax but is directly added to the instructions by the div syntax
*/
function handle($match, $state, $pos, Doku_Handler $handler)
{}
/**
* Create output
*/
function render($mode, Doku_Renderer $renderer, $indata)
{
if($mode == 'xhtml'){
/** @var Doku_Renderer_xhtml $renderer */
$renderer->finishSectionEdit();
return true;
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment