fiwswe I am also learning. Therefore the question, whether that would be correct so?
<?php
class syntax_plugin_localpertag_pertag extends \dokuwiki\Extension\SyntaxPlugin
{
public $MyData = array();
/** @inheritDoc */
public function getType()
{
return 'protected';
}
/** @inheritDoc */
public function getPType()
{
return 'normal';
}
/** @inheritDoc */
public function getSort()
{
return 190;
}
/** @inheritDoc */
public function connectTo($mode)
{
$this->Lexer->addEntryPattern('<MYTAG\b.*?>(?=.*?</MYTAG>)', $mode, 'plugin_localpertag_pertag');
}
/** @inheritDoc */
public function postConnect()
{
$this->Lexer->addExitPattern('</MYTAG>', 'plugin_localpertag_pertag');
}
/** @inheritDoc */
public 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 array();
}
/** @inheritDoc */
public function render($mode, Doku_Renderer $renderer, $data)
{
if ($mode !== 'xhtml') {
return false;
}
global $MyData;
list($state,$match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
$MyData[$state] = $match;
break;
case DOKU_LEXER_UNMATCHED :
$MyData[$state] = $match;
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= 'DOKU_LEXER_ENTER: ' ;
$renderer->doc .= $renderer->cdata($MyData[DOKU_LEXER_ENTER]) .'<br>'. DOKU_LF;
$renderer->doc .= 'DOKU_LEXER_UNMATCHED: ';
$renderer->doc .= $renderer->cdata($MyData[DOKU_LEXER_UNMATCHED]) . DOKU_LF;
$MyData = array();
break;
}
return true;
}
}
The output is correct:
<MYTAG english:french>Some English text.</MYTAG>
<MYTAG german:french>Some German text.</MYTAG>
<MYTAG english:german>Some English text.</MYTAG>
DOKU_LEXER_ENTER: <MYTAG english:french>
DOKU_LEXER_UNMATCHED: Some English text.
DOKU_LEXER_ENTER: <MYTAG german:french>
DOKU_LEXER_UNMATCHED: Some German text.
DOKU_LEXER_ENTER: <MYTAG english:german>
DOKU_LEXER_UNMATCHED: Some English text.
But is this the right way to go?