Hello, andi,
Could you tell me how can i render my syntax accordingly to proper mode handling? Am i doing something wrong? I use getAllowedTypes as well as getType. I am trying use PType even it is not necessary and undesirable because the output is going to the table.
p_render is working perfectly fine. I understand concerns about cache, but why is dokuwiki syntax not working on my output? Did i miss something?
class syntax_plugin_infobox extends DokuWiki_Syntax_Plugin {
/* REGEX PATTERNS */
protected $entry_pattern = '<infobox>\n.*?(?=.*</infobox>)';
protected $row_pattern = '\|.*?(?=.*?)\n';
protected $exit_pattern = '</infobox>';
function getType(){ return 'formatting';}
function getAllowedTypes() { return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); }
function getPType(){ return 'stack';}
function getSort(){ return 195; }
public function connectTo($mode) {
$this->Lexer->addEntryPattern($this->entry_pattern, $mode, 'plugin_infobox'); //new
//Add Internal Pattern Match
$this->Lexer->addPattern($this->row_pattern, 'plugin_infobox');
}
public function postConnect() {
$this->Lexer->addExitPattern($this->exit_pattern, 'plugin_infobox');
}
public function handle($match, $state, $pos, Doku_Handler $handler) {
switch ($state){
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_MATCHED :
//Find The Token And Value (Before '=' remove white space, convert to lower case).
$tokenDiv = strpos($match, '='); //Find Token Value Divider ('=')
$prettyToken = trim(substr($match, 1, ($tokenDiv - 1))); //Everything Before '=', Remove White Space
$token = strtolower($prettyToken); //Convert To Lower Case
$value = trim(substr($match, ($tokenDiv + 1))); //Everything after '='
return array($state, $value, $prettyToken);
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
case DOKU_LEXER_EXIT :
return array($state, '');
case DOKU_LEXER_SPECIAL :
return array($state, $data, '');
}
return array($state, $match);
}
public function render($mode, Doku_Renderer $renderer, $indata){
if (empty($indata)) return false;
list($state, $data, $title) = $indata;
$token = strtolower($title);
if($mode == 'xhtml'){
switch ($state){
case DOKU_LEXER_ENTER :
$renderer->startSectionEdit(0, $indata);
$renderer->doc .= '<table class="infobox" style="border:1px #CCC solid;background-color:#F5F5F5">';
break;
case DOKU_LEXER_MATCHED :
$renderer->doc .= '<tr>';
if ($token) :
switch ($token) {
case 'title';
case 'header';
case 'subtitle';
$renderer->doc .= '<th colspan="2" style="text-align:center; font-size: 125%; font-weight: bold; background:#ccf;">'.$title.'</th>';
break;
case 'image';
$renderer->doc .= '<td colspan="2">'.$renderer->internalmedia($data,'','center','auto','auto','cache','nolink',true).'</td>';
break;
case 'footer';
$renderer->doc .= '<td colspan="2">'.$data.'</td>';
break;
default;
$renderer->doc .= '<th>'.$title.'</th>';
$renderer->doc .= '<td>'.$data.'</td>';
// $instructions = p_get_instructions($data);
// $html = p_render('xhtml', $instructions, $info);
// $renderer->doc .= '<td>'.$html.'</td>';
break;
}
endif;
$renderer->doc .= '</tr>';
break;
case DOKU_LEXER_SPECIAL :
break;
case DOKU_LEXER_UNMATCHED :
// $renderer->doc .= $renderer->_xmlEntities($data);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= '</table>';
$renderer->finishSectionEdit();
break;
}
return true;
}
return false;
}
}