1<?php
2/*
3 * Codeblocks, indented by four spaces
4 */
5
6if(!defined('DOKU_INC')) die();
7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8require_once(DOKU_PLUGIN.'syntax.php');
9
10use dokuwiki\Parsing\Handler\Preformatted;
11
12class syntax_plugin_markdowku_codeblocks extends DokuWiki_Syntax_Plugin {
13
14    function getType()  { return 'protected'; }
15    function getPType() { return 'block'; }
16    function getSort()  { return 199; }
17
18    function connectTo($mode) {
19        $this->Lexer->addEntryPattern(
20            '(?:\n\n|\A\n?)    ',
21            $mode,
22            'plugin_markdowku_codeblocks');
23
24        $this->Lexer->addPattern(
25            '\n    ',
26            'plugin_markdowku_codeblocks');
27    }
28
29    function postConnect() {
30        $this->Lexer->addExitPattern(
31            '\n(?:(?=\n*[ ]{0,3}\S)|\Z)',
32            'plugin_markdowku_codeblocks');
33    }
34
35    function handle($match, $state, $pos, Doku_Handler $handler) {
36        switch ($state) {
37            case DOKU_LEXER_ENTER:
38                $ReWriter = new Preformatted($handler->getCallWriter());
39                $handler->setCallWriter($ReWriter);
40                $handler->_addCall('preformatted_start', array($match), $pos);
41                break;
42            case DOKU_LEXER_MATCHED:
43                $handler->_addCall('preformatted_newline', array($match), $pos);
44                break;
45            case DOKU_LEXER_UNMATCHED:
46                $handler->_addCall('preformatted_content', array($match), $pos);
47                break;
48            case DOKU_LEXER_EXIT:
49                $handler->_addCall('preformatted_end', array(), $pos);
50                $handler->_addCall('preformatted_content', array($match), $pos);
51                $handler->getCallWriter()->process();
52                $ReWriter = & $handler->getCallWriter();
53                $handler->setCallWriter($ReWriter->getCallWriter());
54                break;
55        }
56        return true;
57    }
58
59    function render($mode, Doku_Renderer $renderer, $data) {
60        return false;
61    }
62}
63//Setup VIM: ex: et ts=4 enc=utf-8 :
64