1<?php
2/**
3 * DokuWiki Syntax Plugin InlineJS EmbedCss
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Satoshi Sahara <sahara.satoshi@gmail.com>
7 *
8 * @see also: https://www.dokuwiki.org/devel:css
9 *
10 * Allow inline StyleSheet in DW page.
11 *
12 * SYNTAX:
13 *         <CSS>
14 *           ...
15 *         </CSS>
16 */
17
18require_once(dirname(__FILE__).'/embedder.php');
19
20class syntax_plugin_inlinejs_embedcss extends syntax_plugin_inlinejs_embedder
21{
22    public function getType()
23    {   // Syntax Type
24        return 'protected';
25    }
26
27    public function getPType()
28    {   // Paragraph Type
29        return 'block';
30    }
31
32    /**
33     * Connect pattern to lexer
34     */
35    //protected $mode, $pattern;
36
37    public function preConnect()
38    {
39        // drop 'syntax_' from class name
40        $this->mode = substr(get_class($this), 7);
41
42        // syntax pattern
43        $this->pattern[1] = '<CSS>(?=.*?</CSS>)';
44        $this->pattern[4] = '</CSS>';
45    }
46
47    /**
48     * Plugin features
49     */
50    //protected $code = null;
51
52    /**
53     * Create output
54     */
55    public function render($format, Doku_Renderer $renderer, $data)
56    {
57        list($state, $code) = $data;
58        if ($format != 'xhtml') return false;
59
60        $html = '<style type="text/css">'.DOKU_LF.'<!-- ';
61        $html.= $code;  // raw write
62        $html.= ' -->'.DOKU_LF.'</style>'.DOKU_LF;
63        $renderer->doc .= $html;
64
65        return true;
66    }
67
68}
69