1<?php 2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once(DOKU_PLUGIN.'syntax.php'); 5 6class syntax_plugin_bbcodeextensions_classspan extends DokuWiki_Syntax_Plugin { 7 8 function getType() { return 'formatting'; } 9 function getPType() { return 'normal'; } 10 function getAllowedTypes() { return array('formatting', 'substition', 'protected'); } 11 function getSort() { return 165; } 12 function connectTo($mode) { 13 $this->Lexer->addEntryPattern('\[cs\=.*?\](?=.*?\x5B/cs\x5D)',$mode,'plugin_bbcodeextensions_classspan'); 14 } 15 function postConnect() { $this->Lexer->addExitPattern('\[/cs\]','plugin_bbcodeextensions_classspan'); } 16 17 function handle($match, $state, $pos, Doku_Handler $handler) { 18 switch ($state) { 19 case DOKU_LEXER_ENTER : 20 $omatch= $match; 21 $match = explode('"',substr($match, 3, -1)); 22 return array($state, $match[1], $omatch); 23 case DOKU_LEXER_UNMATCHED : 24 return array($state, $match); 25 case DOKU_LEXER_EXIT : 26 return array($state, ''); 27 } 28 return array(); 29 } 30 31 /** 32 * Create output 33 */ 34 function render($mode, Doku_Renderer $renderer, $data) { 35 if(in_array($mode, ['xhtml', 's5'], true)) { 36 list($state, $match) = $data; 37 $defcl= $this->getConf('class_preffix') ?? 'bbcodeextensions'; 38 39 switch ($state) { 40 case DOKU_LEXER_ENTER : 41 $renderer->doc .= <<<EOF 42<span class="{$defcl} {$match}" > 43EOF; 44 break; 45 46 case DOKU_LEXER_UNMATCHED : 47 $match = $renderer->_xmlEntities($match); 48 $renderer->doc .= $match; 49 break; 50 51 case DOKU_LEXER_EXIT : 52 $renderer->doc .= '</span><!-- bbcodeextensions_span -->'; 53 break; 54 55 } // switch 56 return true; 57 } 58 if(in_array($mode, ['text'], true)) { 59 list($state, $match) = $data; 60 switch ($state) { 61 case DOKU_LEXER_ENTER : 62 break; 63 64 case DOKU_LEXER_UNMATCHED : 65 $renderer->doc .= $match; 66 break; 67 68 case DOKU_LEXER_EXIT : 69 break; 70 } 71 return true; 72 } 73 return false; 74 } 75 76 77} 78