Attached is an image of the result using the plugin as shown below and the following markup:
Markup:
====== PlayGround ======
<page>
<syntax>here I am</syntax>
</page>
Plugin code:
<?php
/**
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_refs extends DokuWiki_Syntax_Plugin {
function getType(){ return 'container'; }
function getAllowedTypes() { return array('formatting', 'substition', 'disabled','container'); }
function getSort(){ return 158; }
function connectTo($mode) {
$this->Lexer->addEntryPattern('<page>',$mode,'plugin_refs');
$this->Lexer->addPattern('<syntax>.*?</syntax>', 'plugin_refs');
}
function postConnect() {
$this->Lexer->addExitPattern('</page>','plugin_refs');
}
function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_ENTER :
return array($state, $match);
case DOKU_LEXER_MATCHED:
preg_match('#<(\w+)>(.*?)<\/\1>#ms', $match, $matches);
return array($state, array($matches[1],$matches[2]));
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
case DOKU_LEXER_EXIT :
return array($state, '');
}
return array();
}
function render($mode, &$renderer, $data) {
// $data is what the function handle return'ed.
if($mode == 'xhtml'){
list($state,$match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER:
$renderer->doc .= '<div style="border:2px solid #1f63b6;-webkit-border-top-left-radius: 9px;-webkit-border-bottom-right-radius: 9px;-moz-border-radius-topleft: 9px;-moz-border-radius-bottomright: 9px;border-top-left-radius: 9px;border-bottom-right-radius: 9px;overflow:hidden">';
break;
case DOKU_LEXER_MATCHED:
list($type,$content) = $match;
if($type == 'syntax') $renderer->doc .= '<div>';
if($type == 'return') $renderer->doc .= '<div>';
// $type will be one of the tags: return,syntax, etc;
// $content will be the content between the tags
$renderer->doc .= $content;
//$renderer->doc .= '</div>';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($match);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= "</div>";
break;
}
return true;
}
return false;
}
}