1<?php 2/** 3 * BBCode plugin: allows BBCode markup familiar from forum software 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Luis Machuca Bezzaza <luis.machuca@gulix.cl> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_bbcode_versalitas extends DokuWiki_Syntax_Plugin { 18 19 function getType() { return 'formatting'; } 20 function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 21 function getSort() { return 105; } 22 function connectTo($mode) { $this->Lexer->addEntryPattern('\[c\](?=.*?\x5B/c\x5D)',$mode,'plugin_bbcode_versalitas'); } 23 function postConnect() { $this->Lexer->addExitPattern('\[/c\]','plugin_bbcode_versalitas'); } 24 25 /** 26 * Handle the match 27 */ 28 function handle($match, $state, $pos, Doku_Handler $handler) { 29 switch ($state) { 30 case DOKU_LEXER_ENTER : 31 $match = substr($match, 3, -1); 32 return array($state, $match); 33 34 case DOKU_LEXER_UNMATCHED : 35 return array($state, $match); 36 37 case DOKU_LEXER_EXIT : 38 return array($state, ''); 39 40 } 41 return array(); 42 } 43 44 /** 45 * Create output 46 */ 47 function render($mode, Doku_Renderer $renderer, $data) { 48 if($mode == 'xhtml') { 49 list($state, $match) = $data; 50 switch ($state) { 51 case DOKU_LEXER_ENTER : 52 $renderer->doc .= '<span style="font-variant:small-caps;">'; 53 break; 54 55 case DOKU_LEXER_UNMATCHED : 56 $renderer->doc .= $renderer->_xmlEntities($match); 57 break; 58 59 case DOKU_LEXER_EXIT : 60 $renderer->doc .= '</span>'; 61 break; 62 63 } 64 return true; 65 } 66 return false; 67 } 68} 69// vim:ts=4:sw=4:et:enc=utf-8: 70