<?php
/**
 * color-Plugin
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Carl-Christian Salvesen <calle@ioslo.net>
 * @version    0.1.20050622
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_color extends DokuWiki_Syntax_Plugin {
 
        /**
        * What kind of syntax are we?
        */
        function getType(){
                return 'formatting';
        }
 
        /**
        * Where to sort in?
        */
        function getSort(){
                return 100;
        }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<color(?=.*\x3C/color\x3E)',$mode,'plugin_color');
    }
 
                function postConnect() {
                        $this->Lexer->addExitPattern('</color>','plugin_color');
                }
 
                /**
                 * Handle the match
                 */
 
 
    function handle($match, $state, $pos) {
                        if ( $state == DOKU_LEXER_UNMATCHED ) {
                                $matches = preg_split('/>/u',$match,2);
                                $matches[0] = trim($matches[0]);
                                if ( trim($matches[0]) == '' ) {
                                        $matches[0] = NULL;
                                }
                                return array($matches[1],$matches[0]);
                        }
                        return TRUE;
    }
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
                        global $conf;
                        if($mode == 'xhtml' && strlen(trim($data[0])) > 0) {
 
                                $renderer->doc .= '<span style="color: '.$data[1].'">'.$data[0].'</span>';
                                return true;
                        }
                        return false;
                }
 
}
