1<?php
2/**
3
4 */
5
6if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8require_once(DOKU_PLUGIN.'syntax.php');
9
10/**
11 * All DokuWiki plugins to extend the parser/rendering mechanism
12 * need to inherit from this class
13 */
14class syntax_plugin_cssperpage extends DokuWiki_Syntax_Plugin {
15
16
17    function getType(){
18        return 'substition';
19    }
20
21
22    function getPType(){
23        return 'block';
24    }
25
26
27    function getSort(){
28        return 199;
29    }
30
31
32    function connectTo($mode) {
33     $this->Lexer->addSpecialPattern('~~cssp_openDIV~~',$mode,'plugin_cssperpage');
34     $this->Lexer->addSpecialPattern('~~cssp_closeDIV~~',$mode,'plugin_cssperpage');
35      $this->Lexer->addSpecialPattern('~~cssp_\w+_openDIV~~',$mode,'plugin_cssperpage');
36
37    }
38
39
40    function handle($match, $state, $pos,  Doku_Handler $handler){
41
42           if(preg_match("/~~cssp_(.*?)_openDIV/",$match,$matches)) {
43            $class=$matches[1];
44            $match = $class . ';' . 'openDIV';
45        }
46       else $match = substr($match,7,-2);
47        switch ($state) {
48          case DOKU_LEXER_SPECIAL :
49           return array($state, $match);
50        }
51        return array($state,"");
52    }
53
54
55    function render($mode,  Doku_Renderer $renderer, $data) {
56        if($mode == 'xhtml'){
57           list($state,$match) = $data;
58            switch ($state) {
59              case DOKU_LEXER_SPECIAL :
60
61               list($class,$rest) = explode(';',$match);
62                if($rest) {
63                    $match = 'openDIV';
64                }
65                 else {
66                     $class ='opencss';
67                }
68                if($match == 'openDIV') {
69                  $renderer->doc .= "\n<div id='css_per_page'  class = '" . $class ."'>\n";
70                }
71                elseif($match == 'closeDIV') {
72                   $renderer->doc .= "\n</div>\n";
73                }
74
75               return true;
76            }
77        }
78        return false;
79    }
80}
81
82?>