1<?php
2/**
3 *
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Myron Turner <turnermm02@shaw.ca>
7 */
8
9// Syntax: <color somecolour/somebackgroundcolour>
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15require_once(DOKU_PLUGIN.'syntax.php');
16
17/**
18 * All DokuWiki plugins to extend the parser/rendering mechanism
19 * need to inherit from this class
20 */
21class syntax_plugin_ckgdoku_font extends DokuWiki_Syntax_Plugin {
22
23
24
25    function getType(){ return 'formatting'; }
26    function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
27    function getSort(){ return 158; }
28    function connectTo($mode) { $this->Lexer->addEntryPattern('<font.*?>(?=.*?</font>)',$mode,'plugin_ckgdoku_font'); }
29    function postConnect() { $this->Lexer->addExitPattern('</font>','plugin_ckgdoku_font'); }
30
31
32    /**
33     * Handle the match
34     */
35    function handle($match, $state, $pos, Doku_Handler $handler){
36
37
38        switch ($state) {
39          case DOKU_LEXER_ENTER :
40                list($size, $face) = preg_split("/\//u", substr($match, 6, -1), 2);
41                if(isset($size) && strpos($size,':') !== false) {
42                        list($size,$weight) = explode(':',$size);
43                        $size = "font-size:$size;";
44                        if(isset($weight) && $weight) {
45                           list($weight,$fstyle) = explode(',',$weight);
46                           $size .= " font-weight:$weight; ";
47                           if($fstyle) $size .= " font-style:$fstyle; ";
48                        }
49
50                }
51                else $size = "font-size:$size;";
52                return array($state, array($size, $face));
53
54          case DOKU_LEXER_UNMATCHED :  return array($state, $match);
55          case DOKU_LEXER_EXIT :       return array($state, '');
56        }
57        return array();
58    }
59
60    /**
61     * Create output
62     */
63    function render($mode, Doku_Renderer $renderer, $data) {
64        if($mode == 'xhtml'){
65            list($state, $match) = $data;
66
67            switch ($state) {
68              case DOKU_LEXER_ENTER :
69                list($style, $face) = $match;
70                if(isset($face)) {
71                    list($face,$fg,$bg) = explode(';;',$face);
72                    if(isset($fg)) {
73                         $color = " color: $fg; ";
74                         $style .= $color;
75
76                    }
77                    if(isset($bg)) {
78                         $color = " background-color: $bg ";
79                         $style .= $color;
80
81                    }
82
83                }
84                $style = "font-family: $face; $style";
85                $renderer->doc .= "<span style='$style'>";
86                break;
87
88              case DOKU_LEXER_UNMATCHED :  $renderer->doc .= $renderer->_xmlEntities($match); break;
89              case DOKU_LEXER_EXIT :       $renderer->doc .= "</span>"; break;
90            }
91            return true;
92        }
93        return false;
94    }
95
96
97}
98?>
99