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 Esther Brunner <esther@kaffeehaus.ch> 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_olist extends DokuWiki_Syntax_Plugin { 18 19 function getType() { return 'container'; } 20 function getPType() { return 'block'; } 21 function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'protected'); } 22 function getSort() { return 105; } 23 function connectTo($mode) { $this->Lexer->addEntryPattern('\[list=.*?\]\s*?\[\*\](?=.*?\x5B/list\x5D)', $mode, 'plugin_bbcode_olist'); } 24 function postConnect() { $this->Lexer->addExitPattern('\[/list\]', 'plugin_bbcode_olist'); } 25 26 /** 27 * Handle the match 28 */ 29 function handle($match, $state, $pos, Doku_Handler $handler) { 30 switch ($state) { 31 case DOKU_LEXER_ENTER : 32 // get the list type 33 $match = substr($match, 6, -4); 34 $match = preg_split('/\]/u',$match,2); 35 return array($state, $match[0]); 36 37 case DOKU_LEXER_UNMATCHED : 38 return array($state, $match); 39 40 case DOKU_LEXER_EXIT : 41 return array($state, ''); 42 43 } 44 return array(); 45 } 46 47 /** 48 * Create output 49 */ 50 function render($mode, Doku_Renderer $renderer, $data) { 51 if($mode == 'xhtml') { 52 list($state, $match) = $data; 53 switch ($state) { 54 case DOKU_LEXER_ENTER : 55 switch ($match) { 56 case 'i': 57 $type = 'lower-roman'; 58 break; 59 case 'I': 60 $type = 'upper-roman'; 61 break; 62 case 'a': 63 $type = 'lower-alpha'; 64 break; 65 case 'A': 66 $type = 'upper-alpha'; 67 break; 68 default: 69 $type = 'decimal'; 70 } 71 $renderer->doc .= '<ol style="list-style-type:'.$type.'"><li class="level1"><div class="li">'; 72 break; 73 74 case DOKU_LEXER_UNMATCHED : 75 $match = $renderer->_xmlEntities($match); 76 $renderer->doc .= str_replace('[*]', '</div></li><li class="level1"><div class="li">', $match); 77 break; 78 79 case DOKU_LEXER_EXIT : 80 $renderer->doc .= '</div></li></ol>'; 81 break; 82 83 } 84 return true; 85 } 86 return false; 87 } 88 89} 90// vim:ts=4:sw=4:et:enc=utf-8: 91