(?=.*?)',$mode,'plugin_mermaid');
}
function postConnect()
{
$this->Lexer->addExitPattern('','plugin_mermaid');
}
/**
* Handle matches of the Mermaid syntax
*/
function handle($match, $state, $pos, Doku_Handler $handler)
{
switch ($state)
{
case DOKU_LEXER_ENTER:
return array($state, $match);
case DOKU_LEXER_UNMATCHED:
return array($state, $match);
case DOKU_LEXER_EXIT:
return array($state, '');
}
return false;
}
/**
* Render xhtml output or metadata
*/
function render($mode, Doku_Renderer $renderer, $indata)
{
if($mode == 'xhtml'){
list($state, $match) = $indata;
switch ($state) {
case DOKU_LEXER_ENTER:
$this->mermaidCounter++;
$values = explode(" ", $match);
$divwidth = count($values) < 2 ? 'auto' : $values[1];
$divheight = count($values) < 3 ? 'auto' : substr($values[2], 0, -1);
$this->mermaidContent .= '';
$this->mermaidContentIfLocked = $this->mermaidContent . 'mermaidCounter.' style="width:'.$divwidth.'; height:'.$divheight.'">';
$this->mermaidContent .= 'mermaidCounter.' style="width:'.$divwidth.'; height:'.$divheight.'">';
break;
case DOKU_LEXER_UNMATCHED:
$explodedMatch = explode("\n", $match);
if(str_starts_with($explodedMatch[1], '%%";
$this->mermaidContent .= '
';
$renderer->doc .= $this->mermaidContent;
$this->mermaidContent = '';
break;
}
return true;
}
return false;
}
/*
* Get the parser instructions suitable for the mermaid
*
*/
function p_get_instructions($text)
{
//import parser classes and mode definitions
require_once DOKU_INC . 'inc/parser/parser.php';
// https://www.dokuwiki.org/devel:parser
// https://www.dokuwiki.org/devel:parser#basic_invocation
// Create the parser and the handler
$Parser = new Parser(new Doku_Handler());
$modes = array();
// add default modes
$std_modes = array( 'internallink', 'media', 'externallink');
foreach($std_modes as $m)
{
$class = 'dokuwiki\\Parsing\\ParserMode\\'.ucfirst($m);
$obj = new $class();
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => $m,
'obj' => $obj
);
}
// add formatting modes
$fmt_modes = array( 'strong', 'emphasis', 'underline', 'monospace', 'subscript', 'superscript', 'deleted');
foreach($fmt_modes as $m)
{
$obj = new \dokuwiki\Parsing\ParserMode\Formatting($m);
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => $m,
'obj' => $obj
);
}
//add modes to parser
foreach($modes as $mode)
{
$Parser->addMode($mode['mode'],$mode['obj']);
}
// Do the parsing
$p = $Parser->parse($text);
return $p;
}
public function p_render($instructions)
{
$Renderer = p_get_renderer('mermaid');
// Loop through the instructions
foreach ($instructions as $instruction) {
if(method_exists($Renderer, $instruction[0])){
call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1] ? $instruction[1] : array());
}
}
return $Renderer->doc;
}
}