xref: /dokuwiki/inc/parser/handler.php (revision 38c6f603e006f27fd6194d1d2c14d3087d0e0cc9)
10cecf9d5Sandi<?php
2fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
352fe2bfbSChris Smithif (!defined('DOKU_PARSER_EOL')) define('DOKU_PARSER_EOL',"\n");   // add this to make handling test cases simpler
4a9c1d2d2SChris Smith
50cecf9d5Sandiclass Doku_Handler {
60cecf9d5Sandi
70ea51e63SMatt Perry    var $Renderer = null;
80cecf9d5Sandi
90ea51e63SMatt Perry    var $CallWriter = null;
100cecf9d5Sandi
110cecf9d5Sandi    var $calls = array();
120cecf9d5Sandi
13e1c10e4dSchris    var $status = array(
1444881bd0Shenning.noren        'section' => false,
15e950d12fSChristopher Smith        'doublequote' => 0,
160cecf9d5Sandi    );
170cecf9d5Sandi
1844881bd0Shenning.noren    var $rewriteBlocks = true;
19b7c441b9SHarry Fuecks
200cecf9d5Sandi    function Doku_Handler() {
2167f9913dSAndreas Gohr        $this->CallWriter = new Doku_Handler_CallWriter($this);
220cecf9d5Sandi    }
230cecf9d5Sandi
24433bef32Sandi    function _addCall($handler, $args, $pos) {
250cecf9d5Sandi        $call = array($handler,$args, $pos);
260cecf9d5Sandi        $this->CallWriter->writeCall($call);
270cecf9d5Sandi    }
280cecf9d5Sandi
2982d61635Spierre.spring    function addPluginCall($plugin, $args, $state, $pos, $match) {
3082d61635Spierre.spring        $call = array('plugin',array($plugin, $args, $state, $match), $pos);
3104ebd214Schris        $this->CallWriter->writeCall($call);
3204ebd214Schris    }
3304ebd214Schris
34433bef32Sandi    function _finalize(){
35e1c10e4dSchris
36f4f02a0fSchris        $this->CallWriter->finalise();
37f4f02a0fSchris
38e1c10e4dSchris        if ( $this->status['section'] ) {
39e1c10e4dSchris            $last_call = end($this->calls);
40e1c10e4dSchris            array_push($this->calls,array('section_close',array(), $last_call[2]));
410cecf9d5Sandi        }
420cecf9d5Sandi
43b7c441b9SHarry Fuecks        if ( $this->rewriteBlocks ) {
4467f9913dSAndreas Gohr            $B = new Doku_Handler_Block();
450cecf9d5Sandi            $this->calls = $B->process($this->calls);
46b7c441b9SHarry Fuecks        }
47e0ad864eSchris
4824bb549bSchris        trigger_event('PARSER_HANDLER_DONE',$this);
490cecf9d5Sandi
500cecf9d5Sandi        array_unshift($this->calls,array('document_start',array(),0));
510cecf9d5Sandi        $last_call = end($this->calls);
520cecf9d5Sandi        array_push($this->calls,array('document_end',array(),$last_call[2]));
530cecf9d5Sandi    }
540cecf9d5Sandi
550cecf9d5Sandi    function fetch() {
560cecf9d5Sandi        $call = each($this->calls);
570cecf9d5Sandi        if ( $call ) {
580cecf9d5Sandi            return $call['value'];
590cecf9d5Sandi        }
6044881bd0Shenning.noren        return false;
610cecf9d5Sandi    }
62ee20e7d1Sandi
63ee20e7d1Sandi
64ee20e7d1Sandi    /**
65ee20e7d1Sandi     * Special plugin handler
66ee20e7d1Sandi     *
67ee20e7d1Sandi     * This handler is called for all modes starting with 'plugin_'.
68ee20e7d1Sandi     * An additional parameter with the plugin name is passed
69ee20e7d1Sandi     *
70ee20e7d1Sandi     * @author Andreas Gohr <andi@splitbrain.org>
71ee20e7d1Sandi     */
72ee20e7d1Sandi    function plugin($match, $state, $pos, $pluginname){
73ee20e7d1Sandi        $data = array($match);
7451a883edSGerrit Uitslag        /** @var DokuWiki_Syntax_Plugin $plugin */
7545d5ad75SGerrit Uitslag        $plugin = plugin_load('syntax',$pluginname);
76a46d0d65SAndreas Gohr        if($plugin != null){
77f02a7d06Schris            $data = $plugin->handle($match, $state, $pos, $this);
78ee20e7d1Sandi        }
7913ecfb18SChris Smith        if ($data !== false) {
8082d61635Spierre.spring            $this->addPluginCall($pluginname,$data,$state,$pos,$match);
8113ecfb18SChris Smith        }
8244881bd0Shenning.noren        return true;
83ee20e7d1Sandi    }
840cecf9d5Sandi
850cecf9d5Sandi    function base($match, $state, $pos) {
860cecf9d5Sandi        switch ( $state ) {
870cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
88433bef32Sandi                $this->_addCall('cdata',array($match), $pos);
8944881bd0Shenning.noren                return true;
900cecf9d5Sandi            break;
910cecf9d5Sandi        }
920cecf9d5Sandi    }
930cecf9d5Sandi
940cecf9d5Sandi    function header($match, $state, $pos) {
95d7e8115fSAndreas Gohr        // get level and title
96a4a2d4cfSAndreas Gohr        $title = trim($match);
97a4a2d4cfSAndreas Gohr        $level = 7 - strspn($title,'=');
98d7e8115fSAndreas Gohr        if($level < 1) $level = 1;
99a4a2d4cfSAndreas Gohr        $title = trim($title,'=');
100a4a2d4cfSAndreas Gohr        $title = trim($title);
1010cecf9d5Sandi
102e1c10e4dSchris        if ($this->status['section']) $this->_addCall('section_close',array(),$pos);
103e1c10e4dSchris
104433bef32Sandi        $this->_addCall('header',array($title,$level,$pos), $pos);
105e1c10e4dSchris
106e1c10e4dSchris        $this->_addCall('section_open',array($level),$pos);
10744881bd0Shenning.noren        $this->status['section'] = true;
10844881bd0Shenning.noren        return true;
1090cecf9d5Sandi    }
1100cecf9d5Sandi
1110cecf9d5Sandi    function notoc($match, $state, $pos) {
112e41c4da9SAndreas Gohr        $this->_addCall('notoc',array(),$pos);
11344881bd0Shenning.noren        return true;
1140cecf9d5Sandi    }
1150cecf9d5Sandi
1169dc2c2afSandi    function nocache($match, $state, $pos) {
1179dc2c2afSandi        $this->_addCall('nocache',array(),$pos);
11844881bd0Shenning.noren        return true;
1199dc2c2afSandi    }
1209dc2c2afSandi
1210cecf9d5Sandi    function linebreak($match, $state, $pos) {
122433bef32Sandi        $this->_addCall('linebreak',array(),$pos);
12344881bd0Shenning.noren        return true;
1240cecf9d5Sandi    }
1250cecf9d5Sandi
1260cecf9d5Sandi    function eol($match, $state, $pos) {
127433bef32Sandi        $this->_addCall('eol',array(),$pos);
12844881bd0Shenning.noren        return true;
1290cecf9d5Sandi    }
1300cecf9d5Sandi
1310cecf9d5Sandi    function hr($match, $state, $pos) {
132433bef32Sandi        $this->_addCall('hr',array(),$pos);
13344881bd0Shenning.noren        return true;
1340cecf9d5Sandi    }
1350cecf9d5Sandi
136433bef32Sandi    function _nestingTag($match, $state, $pos, $name) {
1370cecf9d5Sandi        switch ( $state ) {
1380cecf9d5Sandi            case DOKU_LEXER_ENTER:
139433bef32Sandi                $this->_addCall($name.'_open', array(), $pos);
1400cecf9d5Sandi            break;
1410cecf9d5Sandi            case DOKU_LEXER_EXIT:
142433bef32Sandi                $this->_addCall($name.'_close', array(), $pos);
1430cecf9d5Sandi            break;
1440cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
145433bef32Sandi                $this->_addCall('cdata',array($match), $pos);
1460cecf9d5Sandi            break;
1470cecf9d5Sandi        }
1480cecf9d5Sandi    }
1490cecf9d5Sandi
1500cecf9d5Sandi    function strong($match, $state, $pos) {
151433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'strong');
15244881bd0Shenning.noren        return true;
1530cecf9d5Sandi    }
1540cecf9d5Sandi
1550cecf9d5Sandi    function emphasis($match, $state, $pos) {
156433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'emphasis');
15744881bd0Shenning.noren        return true;
1580cecf9d5Sandi    }
1590cecf9d5Sandi
1600cecf9d5Sandi    function underline($match, $state, $pos) {
161433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'underline');
16244881bd0Shenning.noren        return true;
1630cecf9d5Sandi    }
1640cecf9d5Sandi
1650cecf9d5Sandi    function monospace($match, $state, $pos) {
166433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'monospace');
16744881bd0Shenning.noren        return true;
1680cecf9d5Sandi    }
1690cecf9d5Sandi
1700cecf9d5Sandi    function subscript($match, $state, $pos) {
171433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'subscript');
17244881bd0Shenning.noren        return true;
1730cecf9d5Sandi    }
1740cecf9d5Sandi
1750cecf9d5Sandi    function superscript($match, $state, $pos) {
176433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'superscript');
17744881bd0Shenning.noren        return true;
1780cecf9d5Sandi    }
1790cecf9d5Sandi
1800cecf9d5Sandi    function deleted($match, $state, $pos) {
181433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'deleted');
18244881bd0Shenning.noren        return true;
1830cecf9d5Sandi    }
1840cecf9d5Sandi
1850cecf9d5Sandi
1860cecf9d5Sandi    function footnote($match, $state, $pos) {
1875587e44cSchris//        $this->_nestingTag($match, $state, $pos, 'footnote');
188742c66f8Schris        if (!isset($this->_footnote)) $this->_footnote = false;
1892fe7363dSchris
1905587e44cSchris        switch ( $state ) {
1915587e44cSchris            case DOKU_LEXER_ENTER:
1922fe7363dSchris                // footnotes can not be nested - however due to limitations in lexer it can't be prevented
1932fe7363dSchris                // we will still enter a new footnote mode, we just do nothing
194742c66f8Schris                if ($this->_footnote) {
1952fe7363dSchris                    $this->_addCall('cdata',array($match), $pos);
1962fe7363dSchris                    break;
1972fe7363dSchris                }
1982fe7363dSchris
199742c66f8Schris                $this->_footnote = true;
2002fe7363dSchris
20167f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Nest($this->CallWriter,'footnote_close');
2025587e44cSchris                $this->CallWriter = & $ReWriter;
2034a26ad85Schris                $this->_addCall('footnote_open', array(), $pos);
2045587e44cSchris            break;
2055587e44cSchris            case DOKU_LEXER_EXIT:
2062fe7363dSchris                // check whether we have already exitted the footnote mode, can happen if the modes were nested
207742c66f8Schris                if (!$this->_footnote) {
2082fe7363dSchris                    $this->_addCall('cdata',array($match), $pos);
2092fe7363dSchris                    break;
2102fe7363dSchris                }
2112fe7363dSchris
212742c66f8Schris                $this->_footnote = false;
2132fe7363dSchris
2145587e44cSchris                $this->_addCall('footnote_close', array(), $pos);
2155587e44cSchris                $this->CallWriter->process();
2165587e44cSchris                $ReWriter = & $this->CallWriter;
2175587e44cSchris                $this->CallWriter = & $ReWriter->CallWriter;
2185587e44cSchris            break;
2195587e44cSchris            case DOKU_LEXER_UNMATCHED:
2205587e44cSchris                $this->_addCall('cdata', array($match), $pos);
2215587e44cSchris            break;
2225587e44cSchris        }
22344881bd0Shenning.noren        return true;
2240cecf9d5Sandi    }
2250cecf9d5Sandi
2260cecf9d5Sandi    function listblock($match, $state, $pos) {
2270cecf9d5Sandi        switch ( $state ) {
2280cecf9d5Sandi            case DOKU_LEXER_ENTER:
22967f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_List($this->CallWriter);
2300cecf9d5Sandi                $this->CallWriter = & $ReWriter;
231433bef32Sandi                $this->_addCall('list_open', array($match), $pos);
2320cecf9d5Sandi            break;
2330cecf9d5Sandi            case DOKU_LEXER_EXIT:
234433bef32Sandi                $this->_addCall('list_close', array(), $pos);
2350cecf9d5Sandi                $this->CallWriter->process();
2360cecf9d5Sandi                $ReWriter = & $this->CallWriter;
2370cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
2380cecf9d5Sandi            break;
2390cecf9d5Sandi            case DOKU_LEXER_MATCHED:
240433bef32Sandi                $this->_addCall('list_item', array($match), $pos);
2410cecf9d5Sandi            break;
2420cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
243433bef32Sandi                $this->_addCall('cdata', array($match), $pos);
2440cecf9d5Sandi            break;
2450cecf9d5Sandi        }
24644881bd0Shenning.noren        return true;
2470cecf9d5Sandi    }
2480cecf9d5Sandi
2490cecf9d5Sandi    function unformatted($match, $state, $pos) {
2500cecf9d5Sandi        if ( $state == DOKU_LEXER_UNMATCHED ) {
251433bef32Sandi            $this->_addCall('unformatted',array($match), $pos);
2520cecf9d5Sandi        }
25344881bd0Shenning.noren        return true;
2540cecf9d5Sandi    }
2550cecf9d5Sandi
2560cecf9d5Sandi    function php($match, $state, $pos) {
257df9add72Schris        global $conf;
2580cecf9d5Sandi        if ( $state == DOKU_LEXER_UNMATCHED ) {
259433bef32Sandi            $this->_addCall('php',array($match), $pos);
2600cecf9d5Sandi        }
26144881bd0Shenning.noren        return true;
2620cecf9d5Sandi    }
2630cecf9d5Sandi
26407f89c3cSAnika Henke    function phpblock($match, $state, $pos) {
26507f89c3cSAnika Henke        global $conf;
26607f89c3cSAnika Henke        if ( $state == DOKU_LEXER_UNMATCHED ) {
26707f89c3cSAnika Henke            $this->_addCall('phpblock',array($match), $pos);
26807f89c3cSAnika Henke        }
26907f89c3cSAnika Henke        return true;
27007f89c3cSAnika Henke    }
27107f89c3cSAnika Henke
2720cecf9d5Sandi    function html($match, $state, $pos) {
273df9add72Schris        global $conf;
2740cecf9d5Sandi        if ( $state == DOKU_LEXER_UNMATCHED ) {
275433bef32Sandi            $this->_addCall('html',array($match), $pos);
2760cecf9d5Sandi        }
27744881bd0Shenning.noren        return true;
2780cecf9d5Sandi    }
2790cecf9d5Sandi
28007f89c3cSAnika Henke    function htmlblock($match, $state, $pos) {
28107f89c3cSAnika Henke        global $conf;
28207f89c3cSAnika Henke        if ( $state == DOKU_LEXER_UNMATCHED ) {
28307f89c3cSAnika Henke            $this->_addCall('htmlblock',array($match), $pos);
28407f89c3cSAnika Henke        }
28507f89c3cSAnika Henke        return true;
28607f89c3cSAnika Henke    }
28707f89c3cSAnika Henke
2880cecf9d5Sandi    function preformatted($match, $state, $pos) {
2890cecf9d5Sandi        switch ( $state ) {
2900cecf9d5Sandi            case DOKU_LEXER_ENTER:
29167f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Preformatted($this->CallWriter);
2920cecf9d5Sandi                $this->CallWriter = & $ReWriter;
293433bef32Sandi                $this->_addCall('preformatted_start',array(), $pos);
2940cecf9d5Sandi            break;
2950cecf9d5Sandi            case DOKU_LEXER_EXIT:
296433bef32Sandi                $this->_addCall('preformatted_end',array(), $pos);
2970cecf9d5Sandi                $this->CallWriter->process();
2980cecf9d5Sandi                $ReWriter = & $this->CallWriter;
2990cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
3000cecf9d5Sandi            break;
3010cecf9d5Sandi            case DOKU_LEXER_MATCHED:
302433bef32Sandi                $this->_addCall('preformatted_newline',array(), $pos);
3030cecf9d5Sandi            break;
3040cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
305433bef32Sandi                $this->_addCall('preformatted_content',array($match), $pos);
3060cecf9d5Sandi            break;
3070cecf9d5Sandi        }
3080cecf9d5Sandi
30944881bd0Shenning.noren        return true;
3100cecf9d5Sandi    }
3110cecf9d5Sandi
3120cecf9d5Sandi    function quote($match, $state, $pos) {
3130cecf9d5Sandi
3140cecf9d5Sandi        switch ( $state ) {
3150cecf9d5Sandi
3160cecf9d5Sandi            case DOKU_LEXER_ENTER:
31767f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Quote($this->CallWriter);
3180cecf9d5Sandi                $this->CallWriter = & $ReWriter;
319433bef32Sandi                $this->_addCall('quote_start',array($match), $pos);
3200cecf9d5Sandi            break;
3210cecf9d5Sandi
3220cecf9d5Sandi            case DOKU_LEXER_EXIT:
323433bef32Sandi                $this->_addCall('quote_end',array(), $pos);
3240cecf9d5Sandi                $this->CallWriter->process();
3250cecf9d5Sandi                $ReWriter = & $this->CallWriter;
3260cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
3270cecf9d5Sandi            break;
3280cecf9d5Sandi
3290cecf9d5Sandi            case DOKU_LEXER_MATCHED:
330433bef32Sandi                $this->_addCall('quote_newline',array($match), $pos);
3310cecf9d5Sandi            break;
3320cecf9d5Sandi
3330cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
334433bef32Sandi                $this->_addCall('cdata',array($match), $pos);
3350cecf9d5Sandi            break;
3360cecf9d5Sandi
3370cecf9d5Sandi        }
3380cecf9d5Sandi
33944881bd0Shenning.noren        return true;
3400cecf9d5Sandi    }
3410cecf9d5Sandi
3423d491f75SAndreas Gohr    function file($match, $state, $pos) {
3433d491f75SAndreas Gohr        return $this->code($match, $state, $pos, 'file');
3443d491f75SAndreas Gohr    }
3453d491f75SAndreas Gohr
3463d491f75SAndreas Gohr    function code($match, $state, $pos, $type='code') {
3473d491f75SAndreas Gohr        if ( $state == DOKU_LEXER_UNMATCHED ) {
3484b7f9e70STom N Harris            $matches = explode('>',$match,2);
3493d491f75SAndreas Gohr
3500139312bSAdrian Lang            $param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY);
3510139312bSAdrian Lang            while(count($param) < 2) array_push($param, null);
3520139312bSAdrian Lang
3530139312bSAdrian Lang            // We shortcut html here.
3540139312bSAdrian Lang            if ($param[0] == 'html') $param[0] = 'html4strict';
3550139312bSAdrian Lang            if ($param[0] == '-') $param[0] = null;
3560139312bSAdrian Lang            array_unshift($param, $matches[1]);
3570139312bSAdrian Lang
3580139312bSAdrian Lang            $this->_addCall($type, $param, $pos);
3590cecf9d5Sandi        }
36044881bd0Shenning.noren        return true;
3610cecf9d5Sandi    }
3620cecf9d5Sandi
3630cecf9d5Sandi    function acronym($match, $state, $pos) {
364433bef32Sandi        $this->_addCall('acronym',array($match), $pos);
36544881bd0Shenning.noren        return true;
3660cecf9d5Sandi    }
3670cecf9d5Sandi
3680cecf9d5Sandi    function smiley($match, $state, $pos) {
369433bef32Sandi        $this->_addCall('smiley',array($match), $pos);
37044881bd0Shenning.noren        return true;
3710cecf9d5Sandi    }
3720cecf9d5Sandi
3730cecf9d5Sandi    function wordblock($match, $state, $pos) {
374433bef32Sandi        $this->_addCall('wordblock',array($match), $pos);
37544881bd0Shenning.noren        return true;
3760cecf9d5Sandi    }
3770cecf9d5Sandi
3780cecf9d5Sandi    function entity($match, $state, $pos) {
379433bef32Sandi        $this->_addCall('entity',array($match), $pos);
38044881bd0Shenning.noren        return true;
3810cecf9d5Sandi    }
3820cecf9d5Sandi
3830cecf9d5Sandi    function multiplyentity($match, $state, $pos) {
3840cecf9d5Sandi        preg_match_all('/\d+/',$match,$matches);
385433bef32Sandi        $this->_addCall('multiplyentity',array($matches[0][0],$matches[0][1]), $pos);
38644881bd0Shenning.noren        return true;
3870cecf9d5Sandi    }
3880cecf9d5Sandi
3890cecf9d5Sandi    function singlequoteopening($match, $state, $pos) {
390433bef32Sandi        $this->_addCall('singlequoteopening',array(), $pos);
39144881bd0Shenning.noren        return true;
3920cecf9d5Sandi    }
3930cecf9d5Sandi
3940cecf9d5Sandi    function singlequoteclosing($match, $state, $pos) {
395433bef32Sandi        $this->_addCall('singlequoteclosing',array(), $pos);
39644881bd0Shenning.noren        return true;
3970cecf9d5Sandi    }
3980cecf9d5Sandi
39957d757d1SAndreas Gohr    function apostrophe($match, $state, $pos) {
40057d757d1SAndreas Gohr        $this->_addCall('apostrophe',array(), $pos);
40157d757d1SAndreas Gohr        return true;
40257d757d1SAndreas Gohr    }
40357d757d1SAndreas Gohr
4040cecf9d5Sandi    function doublequoteopening($match, $state, $pos) {
405433bef32Sandi        $this->_addCall('doublequoteopening',array(), $pos);
406e950d12fSChristopher Smith        $this->status['doublequote']++;
40744881bd0Shenning.noren        return true;
4080cecf9d5Sandi    }
4090cecf9d5Sandi
4100cecf9d5Sandi    function doublequoteclosing($match, $state, $pos) {
411e950d12fSChristopher Smith        if ($this->status['doublequote'] <= 0) {
412e950d12fSChristopher Smith            $this->doublequoteopening($match, $state, $pos);
413e950d12fSChristopher Smith        } else {
414433bef32Sandi            $this->_addCall('doublequoteclosing',array(), $pos);
415e950d12fSChristopher Smith            $this->status['doublequote'] = max(0, --$this->status['doublequote']);
416e950d12fSChristopher Smith        }
41744881bd0Shenning.noren        return true;
4180cecf9d5Sandi    }
4190cecf9d5Sandi
4200cecf9d5Sandi    function camelcaselink($match, $state, $pos) {
421433bef32Sandi        $this->_addCall('camelcaselink',array($match), $pos);
42244881bd0Shenning.noren        return true;
4230cecf9d5Sandi    }
4240cecf9d5Sandi
4250cecf9d5Sandi    /*
4260cecf9d5Sandi    */
4270cecf9d5Sandi    function internallink($match, $state, $pos) {
4280cecf9d5Sandi        // Strip the opening and closing markup
4290cecf9d5Sandi        $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);
4300cecf9d5Sandi
4310cecf9d5Sandi        // Split title from URL
4324b7f9e70STom N Harris        $link = explode('|',$link,2);
4330cecf9d5Sandi        if ( !isset($link[1]) ) {
4340ea51e63SMatt Perry            $link[1] = null;
4350cecf9d5Sandi        } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) {
4365578eb8fSandi            // If the title is an image, convert it to an array containing the image details
437b625487dSandi            $link[1] = Doku_Handler_Parse_Media($link[1]);
4380cecf9d5Sandi        }
4390b7c14c2Sandi        $link[0] = trim($link[0]);
4400cecf9d5Sandi
4410e1c636eSandi        //decide which kind of link it is
4420e1c636eSandi
443e08dda3fSAndreas Gohr        if ( preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link[0]) ) {
4440e1c636eSandi            // Interwiki
4454b7f9e70STom N Harris            $interwiki = explode('>',$link[0],2);
446433bef32Sandi            $this->_addCall(
4470cecf9d5Sandi                'interwikilink',
4480cecf9d5Sandi                array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]),
4490cecf9d5Sandi                $pos
4500cecf9d5Sandi                );
45115f1b77cSAndreas Gohr        }elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) {
4520e1c636eSandi            // Windows Share
453433bef32Sandi            $this->_addCall(
4540cecf9d5Sandi                'windowssharelink',
4550cecf9d5Sandi                array($link[0],$link[1]),
4560cecf9d5Sandi                $pos
4570cecf9d5Sandi                );
4584468cb4cSAndreas Gohr        }elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) {
4590e1c636eSandi            // external link (accepts all protocols)
460433bef32Sandi            $this->_addCall(
4610cecf9d5Sandi                    'externallink',
4620cecf9d5Sandi                    array($link[0],$link[1]),
4630cecf9d5Sandi                    $pos
4640cecf9d5Sandi                    );
4650a1d30bfSchris        }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) {
4660a1d30bfSchris            // E-Mail (pattern above is defined in inc/mail.php)
467a6755281Sandi            $this->_addCall(
468a6755281Sandi                'emaillink',
469a6755281Sandi                array($link[0],$link[1]),
470a6755281Sandi                $pos
471a6755281Sandi                );
4720b7c14c2Sandi        }elseif ( preg_match('!^#.+!',$link[0]) ){
4730b7c14c2Sandi            // local link
4740b7c14c2Sandi            $this->_addCall(
4750b7c14c2Sandi                'locallink',
4760b7c14c2Sandi                array(substr($link[0],1),$link[1]),
4770b7c14c2Sandi                $pos
4780b7c14c2Sandi                );
4790e1c636eSandi        }else{
4800e1c636eSandi            // internal link
481433bef32Sandi            $this->_addCall(
4820e1c636eSandi                'internallink',
4830e1c636eSandi                array($link[0],$link[1]),
4840e1c636eSandi                $pos
4850e1c636eSandi                );
4860cecf9d5Sandi        }
4870e1c636eSandi
48844881bd0Shenning.noren        return true;
4890cecf9d5Sandi    }
4900cecf9d5Sandi
4910cecf9d5Sandi    function filelink($match, $state, $pos) {
4920ea51e63SMatt Perry        $this->_addCall('filelink',array($match, null), $pos);
49344881bd0Shenning.noren        return true;
4940cecf9d5Sandi    }
4950cecf9d5Sandi
4960cecf9d5Sandi    function windowssharelink($match, $state, $pos) {
4970ea51e63SMatt Perry        $this->_addCall('windowssharelink',array($match, null), $pos);
49844881bd0Shenning.noren        return true;
4990cecf9d5Sandi    }
5000cecf9d5Sandi
5010cecf9d5Sandi    function media($match, $state, $pos) {
5020cecf9d5Sandi        $p = Doku_Handler_Parse_Media($match);
5030cecf9d5Sandi
504433bef32Sandi        $this->_addCall(
5050cecf9d5Sandi              $p['type'],
506dc673a5bSjoe.lapp              array($p['src'], $p['title'], $p['align'], $p['width'],
507dc673a5bSjoe.lapp                     $p['height'], $p['cache'], $p['linking']),
5080cecf9d5Sandi              $pos
5090cecf9d5Sandi             );
51044881bd0Shenning.noren        return true;
5110cecf9d5Sandi    }
5120cecf9d5Sandi
513b625487dSandi    function rss($match, $state, $pos) {
514b625487dSandi        $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match);
5153db95becSAndreas Gohr
5163db95becSAndreas Gohr        // get params
5173db95becSAndreas Gohr        list($link,$params) = explode(' ',$link,2);
5183db95becSAndreas Gohr
5193db95becSAndreas Gohr        $p = array();
5203db95becSAndreas Gohr        if(preg_match('/\b(\d+)\b/',$params,$match)){
5213db95becSAndreas Gohr            $p['max'] = $match[1];
5223db95becSAndreas Gohr        }else{
5233db95becSAndreas Gohr            $p['max'] = 8;
5243db95becSAndreas Gohr        }
5253db95becSAndreas Gohr        $p['reverse'] = (preg_match('/rev/',$params));
5263db95becSAndreas Gohr        $p['author']  = (preg_match('/\b(by|author)/',$params));
5273db95becSAndreas Gohr        $p['date']    = (preg_match('/\b(date)/',$params));
5283db95becSAndreas Gohr        $p['details'] = (preg_match('/\b(desc|detail)/',$params));
529*38c6f603SRobin H. Johnson        $p['nosort']  = (preg_match('/\b(nosort)\b/',$params));
5303db95becSAndreas Gohr
5310a69dff7Schris        if (preg_match('/\b(\d+)([dhm])\b/',$params,$match)) {
5320a69dff7Schris            $period = array('d' => 86400, 'h' => 3600, 'm' => 60);
5330a69dff7Schris            $p['refresh'] = max(600,$match[1]*$period[$match[2]]);  // n * period in seconds, minimum 10 minutes
5340a69dff7Schris        } else {
5350a69dff7Schris            $p['refresh'] = 14400;   // default to 4 hours
5360a69dff7Schris        }
5370a69dff7Schris
5383db95becSAndreas Gohr        $this->_addCall('rss',array($link,$p),$pos);
53944881bd0Shenning.noren        return true;
540b625487dSandi    }
541b625487dSandi
5420cecf9d5Sandi    function externallink($match, $state, $pos) {
543da9f31c5SAndreas Gohr        $url   = $match;
544da9f31c5SAndreas Gohr        $title = null;
5450cecf9d5Sandi
546da9f31c5SAndreas Gohr        // add protocol on simple short URLs
547da9f31c5SAndreas Gohr        if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')){
548da9f31c5SAndreas Gohr            $title = $url;
549da9f31c5SAndreas Gohr            $url   = 'ftp://'.$url;
550da9f31c5SAndreas Gohr        }
551da9f31c5SAndreas Gohr        if(substr($url,0,3) == 'www' && (substr($url,0,7) != 'http://')){
552da9f31c5SAndreas Gohr            $title = $url;
553da9f31c5SAndreas Gohr            $url = 'http://'.$url;
554da9f31c5SAndreas Gohr        }
555da9f31c5SAndreas Gohr
556da9f31c5SAndreas Gohr        $this->_addCall('externallink',array($url, $title), $pos);
55744881bd0Shenning.noren        return true;
5580cecf9d5Sandi    }
5590cecf9d5Sandi
56071352defSandi    function emaillink($match, $state, $pos) {
5610cecf9d5Sandi        $email = preg_replace(array('/^</','/>$/'),'',$match);
5620ea51e63SMatt Perry        $this->_addCall('emaillink',array($email, null), $pos);
56344881bd0Shenning.noren        return true;
5640cecf9d5Sandi    }
5650cecf9d5Sandi
5660cecf9d5Sandi    function table($match, $state, $pos) {
5670cecf9d5Sandi        switch ( $state ) {
5680cecf9d5Sandi
5690cecf9d5Sandi            case DOKU_LEXER_ENTER:
5700cecf9d5Sandi
57167f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Table($this->CallWriter);
5720cecf9d5Sandi                $this->CallWriter = & $ReWriter;
5730cecf9d5Sandi
57490df9a4dSAdrian Lang                $this->_addCall('table_start', array($pos + 1), $pos);
5750cecf9d5Sandi                if ( trim($match) == '^' ) {
576433bef32Sandi                    $this->_addCall('tableheader', array(), $pos);
5770cecf9d5Sandi                } else {
578433bef32Sandi                    $this->_addCall('tablecell', array(), $pos);
5790cecf9d5Sandi                }
5800cecf9d5Sandi            break;
5810cecf9d5Sandi
5820cecf9d5Sandi            case DOKU_LEXER_EXIT:
58390df9a4dSAdrian Lang                $this->_addCall('table_end', array($pos), $pos);
5840cecf9d5Sandi                $this->CallWriter->process();
5850cecf9d5Sandi                $ReWriter = & $this->CallWriter;
5860cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
5870cecf9d5Sandi            break;
5880cecf9d5Sandi
5890cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
5900cecf9d5Sandi                if ( trim($match) != '' ) {
591433bef32Sandi                    $this->_addCall('cdata',array($match), $pos);
5920cecf9d5Sandi                }
5930cecf9d5Sandi            break;
5940cecf9d5Sandi
5950cecf9d5Sandi            case DOKU_LEXER_MATCHED:
5969ab75d9eSAndreas Gohr                if ( $match == ' ' ){
5979ab75d9eSAndreas Gohr                    $this->_addCall('cdata', array($match), $pos);
59825b97867Shakan.sandell                } else if ( preg_match('/:::/',$match) ) {
59925b97867Shakan.sandell                    $this->_addCall('rowspan', array($match), $pos);
600e205b721SAndreas Gohr                } else if ( preg_match('/\t+/',$match) ) {
6019ab75d9eSAndreas Gohr                    $this->_addCall('table_align', array($match), $pos);
602e205b721SAndreas Gohr                } else if ( preg_match('/ {2,}/',$match) ) {
603433bef32Sandi                    $this->_addCall('table_align', array($match), $pos);
6040cecf9d5Sandi                } else if ( $match == "\n|" ) {
605433bef32Sandi                    $this->_addCall('table_row', array(), $pos);
606433bef32Sandi                    $this->_addCall('tablecell', array(), $pos);
6070cecf9d5Sandi                } else if ( $match == "\n^" ) {
608433bef32Sandi                    $this->_addCall('table_row', array(), $pos);
609433bef32Sandi                    $this->_addCall('tableheader', array(), $pos);
6100cecf9d5Sandi                } else if ( $match == '|' ) {
611433bef32Sandi                    $this->_addCall('tablecell', array(), $pos);
6120cecf9d5Sandi                } else if ( $match == '^' ) {
613433bef32Sandi                    $this->_addCall('tableheader', array(), $pos);
6140cecf9d5Sandi                }
6150cecf9d5Sandi            break;
6160cecf9d5Sandi        }
61744881bd0Shenning.noren        return true;
6180cecf9d5Sandi    }
6190cecf9d5Sandi}
6200cecf9d5Sandi
6210cecf9d5Sandi//------------------------------------------------------------------------
6220cecf9d5Sandifunction Doku_Handler_Parse_Media($match) {
6230cecf9d5Sandi
6240cecf9d5Sandi    // Strip the opening and closing markup
6250cecf9d5Sandi    $link = preg_replace(array('/^\{\{/','/\}\}$/u'),'',$match);
6260cecf9d5Sandi
6270cecf9d5Sandi    // Split title from URL
6284b7f9e70STom N Harris    $link = explode('|',$link,2);
6290cecf9d5Sandi
6300cecf9d5Sandi    // Check alignment
6310cecf9d5Sandi    $ralign = (bool)preg_match('/^ /',$link[0]);
6320cecf9d5Sandi    $lalign = (bool)preg_match('/ $/',$link[0]);
6330cecf9d5Sandi
6340cecf9d5Sandi    // Logic = what's that ;)...
6350cecf9d5Sandi    if ( $lalign & $ralign ) {
6360cecf9d5Sandi        $align = 'center';
6370cecf9d5Sandi    } else if ( $ralign ) {
6380cecf9d5Sandi        $align = 'right';
6390cecf9d5Sandi    } else if ( $lalign ) {
6400cecf9d5Sandi        $align = 'left';
6410cecf9d5Sandi    } else {
6420ea51e63SMatt Perry        $align = null;
6430cecf9d5Sandi    }
6440cecf9d5Sandi
6450cecf9d5Sandi    // The title...
6460cecf9d5Sandi    if ( !isset($link[1]) ) {
6470ea51e63SMatt Perry        $link[1] = null;
6480cecf9d5Sandi    }
6490cecf9d5Sandi
6504826ab45Sandi    //remove aligning spaces
6514826ab45Sandi    $link[0] = trim($link[0]);
6520cecf9d5Sandi
6534826ab45Sandi    //split into src and parameters (using the very last questionmark)
6544826ab45Sandi    $pos = strrpos($link[0], '?');
6554826ab45Sandi    if($pos !== false){
6564826ab45Sandi        $src   = substr($link[0],0,$pos);
6574826ab45Sandi        $param = substr($link[0],$pos+1);
6580cecf9d5Sandi    }else{
6594826ab45Sandi        $src   = $link[0];
6604826ab45Sandi        $param = '';
6610cecf9d5Sandi    }
6620cecf9d5Sandi
6634826ab45Sandi    //parse width and height
6644826ab45Sandi    if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){
665443e135dSChristopher Smith        !empty($size[1]) ? $w = $size[1] : $w = null;
666443e135dSChristopher Smith        !empty($size[3]) ? $h = $size[3] : $h = null;
667fc1c55b1Shfuecks    } else {
6680ea51e63SMatt Perry        $w = null;
6690ea51e63SMatt Perry        $h = null;
6700cecf9d5Sandi    }
6710cecf9d5Sandi
672dc673a5bSjoe.lapp    //get linking command
673d35ab615Shenning.noren    if(preg_match('/nolink/i',$param)){
674dc673a5bSjoe.lapp        $linking = 'nolink';
675d35ab615Shenning.noren    }else if(preg_match('/direct/i',$param)){
676dc673a5bSjoe.lapp        $linking = 'direct';
6778acb3108SAndreas Gohr    }else if(preg_match('/linkonly/i',$param)){
6788acb3108SAndreas Gohr        $linking = 'linkonly';
679dc673a5bSjoe.lapp    }else{
680dc673a5bSjoe.lapp        $linking = 'details';
681dc673a5bSjoe.lapp    }
682dc673a5bSjoe.lapp
6834826ab45Sandi    //get caching command
6844826ab45Sandi    if (preg_match('/(nocache|recache)/i',$param,$cachemode)){
6854826ab45Sandi        $cache = $cachemode[1];
6860cecf9d5Sandi    }else{
6874826ab45Sandi        $cache = 'cache';
6880cecf9d5Sandi    }
6890cecf9d5Sandi
6900cecf9d5Sandi    // Check whether this is a local or remote image
6913e7e6067SKlap-in    if ( media_isexternal($src) ) {
6924826ab45Sandi        $call = 'externalmedia';
6930cecf9d5Sandi    } else {
6944826ab45Sandi        $call = 'internalmedia';
6950cecf9d5Sandi    }
6960cecf9d5Sandi
6970cecf9d5Sandi    $params = array(
6980cecf9d5Sandi        'type'=>$call,
6994826ab45Sandi        'src'=>$src,
7000cecf9d5Sandi        'title'=>$link[1],
7010cecf9d5Sandi        'align'=>$align,
7024826ab45Sandi        'width'=>$w,
7034826ab45Sandi        'height'=>$h,
7040cecf9d5Sandi        'cache'=>$cache,
705dc673a5bSjoe.lapp        'linking'=>$linking,
7060cecf9d5Sandi    );
7070cecf9d5Sandi
7080cecf9d5Sandi    return $params;
7090cecf9d5Sandi}
7100cecf9d5Sandi
7110cecf9d5Sandi//------------------------------------------------------------------------
7120cecf9d5Sandiclass Doku_Handler_CallWriter {
7130cecf9d5Sandi
7140cecf9d5Sandi    var $Handler;
7150cecf9d5Sandi
71642ea7f44SGerrit Uitslag    /**
71742ea7f44SGerrit Uitslag     * @param Doku_Handler $Handler
71842ea7f44SGerrit Uitslag     */
7190cecf9d5Sandi    function Doku_Handler_CallWriter(& $Handler) {
7200cecf9d5Sandi        $this->Handler = & $Handler;
7210cecf9d5Sandi    }
7220cecf9d5Sandi
7230cecf9d5Sandi    function writeCall($call) {
7240cecf9d5Sandi        $this->Handler->calls[] = $call;
7250cecf9d5Sandi    }
7260cecf9d5Sandi
7270cecf9d5Sandi    function writeCalls($calls) {
7280cecf9d5Sandi        $this->Handler->calls = array_merge($this->Handler->calls, $calls);
7290cecf9d5Sandi    }
730f4f02a0fSchris
731f4f02a0fSchris    // function is required, but since this call writer is first/highest in
732f4f02a0fSchris    // the chain it is not required to do anything
733f4f02a0fSchris    function finalise() {
7343893df8eSChristopher Smith        unset($this->Handler);
735f4f02a0fSchris    }
7360cecf9d5Sandi}
7370cecf9d5Sandi
7380cecf9d5Sandi//------------------------------------------------------------------------
7395587e44cSchris/**
7405587e44cSchris * Generic call writer class to handle nesting of rendering instructions
7415587e44cSchris * within a render instruction. Also see nest() method of renderer base class
7425587e44cSchris *
7435587e44cSchris * @author    Chris Smith <chris@jalakai.co.uk>
7445587e44cSchris */
7455587e44cSchrisclass Doku_Handler_Nest {
7465587e44cSchris
7475587e44cSchris    var $CallWriter;
7485587e44cSchris    var $calls = array();
7495587e44cSchris
7505587e44cSchris    var $closingInstruction;
7515587e44cSchris
7525587e44cSchris    /**
7535587e44cSchris     * constructor
7545587e44cSchris     *
75542ea7f44SGerrit Uitslag     * @param  Doku_Handler_CallWriter $CallWriter     the renderers current call writer
7565587e44cSchris     * @param  string     $close          closing instruction name, this is required to properly terminate the
7575587e44cSchris     *                                    syntax mode if the document ends without a closing pattern
7585587e44cSchris     */
7595587e44cSchris    function Doku_Handler_Nest(& $CallWriter, $close="nest_close") {
7605587e44cSchris        $this->CallWriter = & $CallWriter;
7615587e44cSchris
7625587e44cSchris        $this->closingInstruction = $close;
7635587e44cSchris    }
7645587e44cSchris
7655587e44cSchris    function writeCall($call) {
7665587e44cSchris        $this->calls[] = $call;
7675587e44cSchris    }
7685587e44cSchris
7695587e44cSchris    function writeCalls($calls) {
7705587e44cSchris        $this->calls = array_merge($this->calls, $calls);
7715587e44cSchris    }
7725587e44cSchris
7735587e44cSchris    function finalise() {
7745587e44cSchris        $last_call = end($this->calls);
7755587e44cSchris        $this->writeCall(array($this->closingInstruction,array(), $last_call[2]));
7765587e44cSchris
7775587e44cSchris        $this->process();
7785587e44cSchris        $this->CallWriter->finalise();
7793893df8eSChristopher Smith        unset($this->CallWriter);
7805587e44cSchris    }
7815587e44cSchris
7825587e44cSchris    function process() {
78341624b31SChris Smith        // merge consecutive cdata
78441624b31SChris Smith        $unmerged_calls = $this->calls;
78541624b31SChris Smith        $this->calls = array();
78641624b31SChris Smith
78741624b31SChris Smith        foreach ($unmerged_calls as $call) $this->addCall($call);
78841624b31SChris Smith
7895587e44cSchris        $first_call = reset($this->calls);
7905587e44cSchris        $this->CallWriter->writeCall(array("nest", array($this->calls), $first_call[2]));
7915587e44cSchris    }
79241624b31SChris Smith
79341624b31SChris Smith    function addCall($call) {
79441624b31SChris Smith        $key = count($this->calls);
79541624b31SChris Smith        if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
79641624b31SChris Smith            $this->calls[$key-1][1][0] .= $call[1][0];
79773c47f3dSChris Smith        } else if ($call[0] == 'eol') {
79873c47f3dSChris Smith            // do nothing (eol shouldn't be allowed, to counter preformatted fix in #1652 & #1699)
79941624b31SChris Smith        } else {
80041624b31SChris Smith            $this->calls[] = $call;
80141624b31SChris Smith        }
80241624b31SChris Smith    }
8035587e44cSchris}
8045587e44cSchris
8050cecf9d5Sandiclass Doku_Handler_List {
8060cecf9d5Sandi
8070cecf9d5Sandi    var $CallWriter;
8080cecf9d5Sandi
8090cecf9d5Sandi    var $calls = array();
8100cecf9d5Sandi    var $listCalls = array();
8110cecf9d5Sandi    var $listStack = array();
8120cecf9d5Sandi
81310bcc8aaSChristopher Smith    const NODE = 1;
81410bcc8aaSChristopher Smith
8150cecf9d5Sandi    function Doku_Handler_List(& $CallWriter) {
8160cecf9d5Sandi        $this->CallWriter = & $CallWriter;
8170cecf9d5Sandi    }
8180cecf9d5Sandi
8190cecf9d5Sandi    function writeCall($call) {
8200cecf9d5Sandi        $this->calls[] = $call;
8210cecf9d5Sandi    }
8220cecf9d5Sandi
8230cecf9d5Sandi    // Probably not needed but just in case...
8240cecf9d5Sandi    function writeCalls($calls) {
8250cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
826f4f02a0fSchris#        $this->CallWriter->writeCalls($this->calls);
827f4f02a0fSchris    }
828f4f02a0fSchris
829f4f02a0fSchris    function finalise() {
830f4f02a0fSchris        $last_call = end($this->calls);
831f4f02a0fSchris        $this->writeCall(array('list_close',array(), $last_call[2]));
832f4f02a0fSchris
833f4f02a0fSchris        $this->process();
834f4f02a0fSchris        $this->CallWriter->finalise();
8353893df8eSChristopher Smith        unset($this->CallWriter);
8360cecf9d5Sandi    }
8370cecf9d5Sandi
8380cecf9d5Sandi    //------------------------------------------------------------------------
8390cecf9d5Sandi    function process() {
840f4f02a0fSchris
8410cecf9d5Sandi        foreach ( $this->calls as $call ) {
8420cecf9d5Sandi            switch ($call[0]) {
8430cecf9d5Sandi                case 'list_item':
8440cecf9d5Sandi                    $this->listOpen($call);
8450cecf9d5Sandi                break;
8460cecf9d5Sandi                case 'list_open':
8470cecf9d5Sandi                    $this->listStart($call);
8480cecf9d5Sandi                break;
8490cecf9d5Sandi                case 'list_close':
8500cecf9d5Sandi                    $this->listEnd($call);
8510cecf9d5Sandi                break;
8520cecf9d5Sandi                default:
8530cecf9d5Sandi                    $this->listContent($call);
8540cecf9d5Sandi                break;
8550cecf9d5Sandi            }
8560cecf9d5Sandi        }
8570cecf9d5Sandi
8580cecf9d5Sandi        $this->CallWriter->writeCalls($this->listCalls);
8590cecf9d5Sandi    }
8600cecf9d5Sandi
8610cecf9d5Sandi    //------------------------------------------------------------------------
8620cecf9d5Sandi    function listStart($call) {
8630cecf9d5Sandi        $depth = $this->interpretSyntax($call[1][0], $listType);
8640cecf9d5Sandi
8650cecf9d5Sandi        $this->initialDepth = $depth;
86610bcc8aaSChristopher Smith        //                   array(list type, current depth, index of current listitem_open)
86710bcc8aaSChristopher Smith        $this->listStack[] = array($listType, $depth, 1);
8680cecf9d5Sandi
8690cecf9d5Sandi        $this->listCalls[] = array('list'.$listType.'_open',array(),$call[2]);
8700cecf9d5Sandi        $this->listCalls[] = array('listitem_open',array(1),$call[2]);
8710cecf9d5Sandi        $this->listCalls[] = array('listcontent_open',array(),$call[2]);
8720cecf9d5Sandi    }
8730cecf9d5Sandi
8740cecf9d5Sandi    //------------------------------------------------------------------------
8750cecf9d5Sandi    function listEnd($call) {
87644881bd0Shenning.noren        $closeContent = true;
8770cecf9d5Sandi
8780cecf9d5Sandi        while ( $list = array_pop($this->listStack) ) {
8790cecf9d5Sandi            if ( $closeContent ) {
8800cecf9d5Sandi                $this->listCalls[] = array('listcontent_close',array(),$call[2]);
88144881bd0Shenning.noren                $closeContent = false;
8820cecf9d5Sandi            }
8830cecf9d5Sandi            $this->listCalls[] = array('listitem_close',array(),$call[2]);
8840cecf9d5Sandi            $this->listCalls[] = array('list'.$list[0].'_close', array(), $call[2]);
8850cecf9d5Sandi        }
8860cecf9d5Sandi    }
8870cecf9d5Sandi
8880cecf9d5Sandi    //------------------------------------------------------------------------
8890cecf9d5Sandi    function listOpen($call) {
8900cecf9d5Sandi        $depth = $this->interpretSyntax($call[1][0], $listType);
8910cecf9d5Sandi        $end = end($this->listStack);
89210bcc8aaSChristopher Smith        $key = key($this->listStack);
8930cecf9d5Sandi
8940cecf9d5Sandi        // Not allowed to be shallower than initialDepth
8950cecf9d5Sandi        if ( $depth < $this->initialDepth ) {
8960cecf9d5Sandi            $depth = $this->initialDepth;
8970cecf9d5Sandi        }
8980cecf9d5Sandi
8990cecf9d5Sandi        //------------------------------------------------------------------------
9000cecf9d5Sandi        if ( $depth == $end[1] ) {
9010cecf9d5Sandi
9020cecf9d5Sandi            // Just another item in the list...
9030cecf9d5Sandi            if ( $listType == $end[0] ) {
9040cecf9d5Sandi                $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9050cecf9d5Sandi                $this->listCalls[] = array('listitem_close',array(),$call[2]);
9060cecf9d5Sandi                $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);
9070cecf9d5Sandi                $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9080cecf9d5Sandi
90910bcc8aaSChristopher Smith                // new list item, update list stack's index into current listitem_open
91010bcc8aaSChristopher Smith                $this->listStack[$key][2] = count($this->listCalls) - 2;
91110bcc8aaSChristopher Smith
9120cecf9d5Sandi            // Switched list type...
9130cecf9d5Sandi            } else {
9140cecf9d5Sandi
9150cecf9d5Sandi                $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9160cecf9d5Sandi                $this->listCalls[] = array('listitem_close',array(),$call[2]);
9170cecf9d5Sandi                $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);
9180cecf9d5Sandi                $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
9190cecf9d5Sandi                $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
9200cecf9d5Sandi                $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9210cecf9d5Sandi
9220cecf9d5Sandi                array_pop($this->listStack);
92310bcc8aaSChristopher Smith                $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
9240cecf9d5Sandi            }
9250cecf9d5Sandi
9260cecf9d5Sandi        //------------------------------------------------------------------------
9270cecf9d5Sandi        // Getting deeper...
9280cecf9d5Sandi        } else if ( $depth > $end[1] ) {
9290cecf9d5Sandi
9300cecf9d5Sandi            $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9310cecf9d5Sandi            $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
9320cecf9d5Sandi            $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
9330cecf9d5Sandi            $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9340cecf9d5Sandi
93510bcc8aaSChristopher Smith            // set the node/leaf state of this item's parent listitem_open to NODE
93610bcc8aaSChristopher Smith            $this->listCalls[$this->listStack[$key][2]][1][1] = self::NODE;
93710bcc8aaSChristopher Smith
93810bcc8aaSChristopher Smith            $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
9390cecf9d5Sandi
9400cecf9d5Sandi        //------------------------------------------------------------------------
9410cecf9d5Sandi        // Getting shallower ( $depth < $end[1] )
9420cecf9d5Sandi        } else {
9430cecf9d5Sandi            $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9440cecf9d5Sandi            $this->listCalls[] = array('listitem_close',array(),$call[2]);
9450cecf9d5Sandi            $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);
9460cecf9d5Sandi
9470cecf9d5Sandi            // Throw away the end - done
9480cecf9d5Sandi            array_pop($this->listStack);
9490cecf9d5Sandi
9500cecf9d5Sandi            while (1) {
9510cecf9d5Sandi                $end = end($this->listStack);
95210bcc8aaSChristopher Smith                $key = key($this->listStack);
9530cecf9d5Sandi
9540cecf9d5Sandi                if ( $end[1] <= $depth ) {
9550cecf9d5Sandi
9560cecf9d5Sandi                    // Normalize depths
9570cecf9d5Sandi                    $depth = $end[1];
9580cecf9d5Sandi
9590cecf9d5Sandi                    $this->listCalls[] = array('listitem_close',array(),$call[2]);
9600cecf9d5Sandi
9610cecf9d5Sandi                    if ( $end[0] == $listType ) {
9620cecf9d5Sandi                        $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);
9630cecf9d5Sandi                        $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9640cecf9d5Sandi
96510bcc8aaSChristopher Smith                        // new list item, update list stack's index into current listitem_open
96610bcc8aaSChristopher Smith                        $this->listStack[$key][2] = count($this->listCalls) - 2;
96710bcc8aaSChristopher Smith
9680cecf9d5Sandi                    } else {
9690cecf9d5Sandi                        // Switching list type...
9700cecf9d5Sandi                        $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);
9710cecf9d5Sandi                        $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
9720cecf9d5Sandi                        $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
9730cecf9d5Sandi                        $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9740cecf9d5Sandi
9750cecf9d5Sandi                        array_pop($this->listStack);
97610bcc8aaSChristopher Smith                        $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
9770cecf9d5Sandi                    }
9780cecf9d5Sandi
9790cecf9d5Sandi                    break;
9800cecf9d5Sandi
9810cecf9d5Sandi                // Haven't dropped down far enough yet.... ( $end[1] > $depth )
9820cecf9d5Sandi                } else {
9830cecf9d5Sandi
9840cecf9d5Sandi                    $this->listCalls[] = array('listitem_close',array(),$call[2]);
9850cecf9d5Sandi                    $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);
9860cecf9d5Sandi
9870cecf9d5Sandi                    array_pop($this->listStack);
9880cecf9d5Sandi
9890cecf9d5Sandi                }
9900cecf9d5Sandi
9910cecf9d5Sandi            }
9920cecf9d5Sandi
9930cecf9d5Sandi        }
9940cecf9d5Sandi    }
9950cecf9d5Sandi
9960cecf9d5Sandi    //------------------------------------------------------------------------
9970cecf9d5Sandi    function listContent($call) {
9980cecf9d5Sandi        $this->listCalls[] = $call;
9990cecf9d5Sandi    }
10000cecf9d5Sandi
10010cecf9d5Sandi    //------------------------------------------------------------------------
10020cecf9d5Sandi    function interpretSyntax($match, & $type) {
10030cecf9d5Sandi        if ( substr($match,-1) == '*' ) {
10040cecf9d5Sandi            $type = 'u';
10050cecf9d5Sandi        } else {
10060cecf9d5Sandi            $type = 'o';
10070cecf9d5Sandi        }
10084b7f9e70STom N Harris        // Is the +1 needed? It used to be count(explode(...))
10094b7f9e70STom N Harris        // but I don't think the number is seen outside this handler
10104b7f9e70STom N Harris        return substr_count(str_replace("\t",'  ',$match), '  ') + 1;
10110cecf9d5Sandi    }
10120cecf9d5Sandi}
10130cecf9d5Sandi
10140cecf9d5Sandi//------------------------------------------------------------------------
10150cecf9d5Sandiclass Doku_Handler_Preformatted {
10160cecf9d5Sandi
10170cecf9d5Sandi    var $CallWriter;
10180cecf9d5Sandi
10190cecf9d5Sandi    var $calls = array();
10200cecf9d5Sandi    var $pos;
10210cecf9d5Sandi    var $text ='';
10220cecf9d5Sandi
10230cecf9d5Sandi
10240cecf9d5Sandi
10250cecf9d5Sandi    function Doku_Handler_Preformatted(& $CallWriter) {
10260cecf9d5Sandi        $this->CallWriter = & $CallWriter;
10270cecf9d5Sandi    }
10280cecf9d5Sandi
10290cecf9d5Sandi    function writeCall($call) {
10300cecf9d5Sandi        $this->calls[] = $call;
10310cecf9d5Sandi    }
10320cecf9d5Sandi
10330cecf9d5Sandi    // Probably not needed but just in case...
10340cecf9d5Sandi    function writeCalls($calls) {
10350cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
1036f4f02a0fSchris#        $this->CallWriter->writeCalls($this->calls);
1037f4f02a0fSchris    }
1038f4f02a0fSchris
1039f4f02a0fSchris    function finalise() {
1040f4f02a0fSchris        $last_call = end($this->calls);
1041f4f02a0fSchris        $this->writeCall(array('preformatted_end',array(), $last_call[2]));
1042f4f02a0fSchris
1043f4f02a0fSchris        $this->process();
1044f4f02a0fSchris        $this->CallWriter->finalise();
10453893df8eSChristopher Smith        unset($this->CallWriter);
10460cecf9d5Sandi    }
10470cecf9d5Sandi
10480cecf9d5Sandi    function process() {
10490cecf9d5Sandi        foreach ( $this->calls as $call ) {
10500cecf9d5Sandi            switch ($call[0]) {
10510cecf9d5Sandi                case 'preformatted_start':
10520cecf9d5Sandi                    $this->pos = $call[2];
10530cecf9d5Sandi                break;
10540cecf9d5Sandi                case 'preformatted_newline':
10550cecf9d5Sandi                    $this->text .= "\n";
10560cecf9d5Sandi                break;
10570cecf9d5Sandi                case 'preformatted_content':
10580cecf9d5Sandi                    $this->text .= $call[1][0];
10590cecf9d5Sandi                break;
10600cecf9d5Sandi                case 'preformatted_end':
106193a34bf3SChris Smith                    if (trim($this->text)) {
10620cecf9d5Sandi                        $this->CallWriter->writeCall(array('preformatted',array($this->text),$this->pos));
106393a34bf3SChris Smith                    }
106495c19ce7SChris Smith                    // see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open
106595c19ce7SChris Smith                    $this->CallWriter->writeCall(array('eol',array(),$this->pos));
106695c19ce7SChris Smith                    $this->CallWriter->writeCall(array('eol',array(),$this->pos));
10670cecf9d5Sandi                break;
10680cecf9d5Sandi            }
10690cecf9d5Sandi        }
10700cecf9d5Sandi    }
1071f4f02a0fSchris
10720cecf9d5Sandi}
10730cecf9d5Sandi
10740cecf9d5Sandi//------------------------------------------------------------------------
10750cecf9d5Sandiclass Doku_Handler_Quote {
10760cecf9d5Sandi
10770cecf9d5Sandi    var $CallWriter;
10780cecf9d5Sandi
10790cecf9d5Sandi    var $calls = array();
10800cecf9d5Sandi
10810cecf9d5Sandi    var $quoteCalls = array();
10820cecf9d5Sandi
10830cecf9d5Sandi    function Doku_Handler_Quote(& $CallWriter) {
10840cecf9d5Sandi        $this->CallWriter = & $CallWriter;
10850cecf9d5Sandi    }
10860cecf9d5Sandi
10870cecf9d5Sandi    function writeCall($call) {
10880cecf9d5Sandi        $this->calls[] = $call;
10890cecf9d5Sandi    }
10900cecf9d5Sandi
10910cecf9d5Sandi    // Probably not needed but just in case...
10920cecf9d5Sandi    function writeCalls($calls) {
10930cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
1094f4f02a0fSchris    }
1095f4f02a0fSchris
1096f4f02a0fSchris    function finalise() {
1097f4f02a0fSchris        $last_call = end($this->calls);
1098f4f02a0fSchris        $this->writeCall(array('quote_end',array(), $last_call[2]));
1099f4f02a0fSchris
1100f4f02a0fSchris        $this->process();
1101f4f02a0fSchris        $this->CallWriter->finalise();
11023893df8eSChristopher Smith        unset($this->CallWriter);
11030cecf9d5Sandi    }
11040cecf9d5Sandi
11050cecf9d5Sandi    function process() {
11060cecf9d5Sandi
11070cecf9d5Sandi        $quoteDepth = 1;
11080cecf9d5Sandi
11090cecf9d5Sandi        foreach ( $this->calls as $call ) {
11100cecf9d5Sandi            switch ($call[0]) {
11110cecf9d5Sandi
11120cecf9d5Sandi                case 'quote_start':
11130cecf9d5Sandi
11140cecf9d5Sandi                    $this->quoteCalls[] = array('quote_open',array(),$call[2]);
11150cecf9d5Sandi
11160cecf9d5Sandi                case 'quote_newline':
11170cecf9d5Sandi
11180cecf9d5Sandi                    $quoteLength = $this->getDepth($call[1][0]);
11190cecf9d5Sandi
11200cecf9d5Sandi                    if ( $quoteLength > $quoteDepth ) {
11210cecf9d5Sandi                        $quoteDiff = $quoteLength - $quoteDepth;
11220cecf9d5Sandi                        for ( $i = 1; $i <= $quoteDiff; $i++ ) {
11230cecf9d5Sandi                            $this->quoteCalls[] = array('quote_open',array(),$call[2]);
11240cecf9d5Sandi                        }
11250cecf9d5Sandi                    } else if ( $quoteLength < $quoteDepth ) {
11260cecf9d5Sandi                        $quoteDiff = $quoteDepth - $quoteLength;
11270cecf9d5Sandi                        for ( $i = 1; $i <= $quoteDiff; $i++ ) {
11280cecf9d5Sandi                            $this->quoteCalls[] = array('quote_close',array(),$call[2]);
11290cecf9d5Sandi                        }
113026426c64Schris                    } else {
113126426c64Schris                        if ($call[0] != 'quote_start') $this->quoteCalls[] = array('linebreak',array(),$call[2]);
11320cecf9d5Sandi                    }
11330cecf9d5Sandi
11340cecf9d5Sandi                    $quoteDepth = $quoteLength;
11350cecf9d5Sandi
11360cecf9d5Sandi                break;
11370cecf9d5Sandi
11380cecf9d5Sandi                case 'quote_end':
11390cecf9d5Sandi
11400cecf9d5Sandi                    if ( $quoteDepth > 1 ) {
11410cecf9d5Sandi                        $quoteDiff = $quoteDepth - 1;
11420cecf9d5Sandi                        for ( $i = 1; $i <= $quoteDiff; $i++ ) {
11430cecf9d5Sandi                            $this->quoteCalls[] = array('quote_close',array(),$call[2]);
11440cecf9d5Sandi                        }
11450cecf9d5Sandi                    }
11460cecf9d5Sandi
11470cecf9d5Sandi                    $this->quoteCalls[] = array('quote_close',array(),$call[2]);
11480cecf9d5Sandi
11490cecf9d5Sandi                    $this->CallWriter->writeCalls($this->quoteCalls);
11500cecf9d5Sandi                break;
11510cecf9d5Sandi
11520cecf9d5Sandi                default:
11530cecf9d5Sandi                    $this->quoteCalls[] = $call;
11540cecf9d5Sandi                break;
11550cecf9d5Sandi            }
11560cecf9d5Sandi        }
11570cecf9d5Sandi    }
11580cecf9d5Sandi
11590cecf9d5Sandi    function getDepth($marker) {
11600cecf9d5Sandi        preg_match('/>{1,}/', $marker, $matches);
11610cecf9d5Sandi        $quoteLength = strlen($matches[0]);
11620cecf9d5Sandi        return $quoteLength;
11630cecf9d5Sandi    }
11640cecf9d5Sandi}
11650cecf9d5Sandi
11660cecf9d5Sandi//------------------------------------------------------------------------
11670cecf9d5Sandiclass Doku_Handler_Table {
11680cecf9d5Sandi
11690cecf9d5Sandi    var $CallWriter;
11700cecf9d5Sandi
11710cecf9d5Sandi    var $calls = array();
11720cecf9d5Sandi    var $tableCalls = array();
11730cecf9d5Sandi    var $maxCols = 0;
11740cecf9d5Sandi    var $maxRows = 1;
11750cecf9d5Sandi    var $currentCols = 0;
117644881bd0Shenning.noren    var $firstCell = false;
11770cecf9d5Sandi    var $lastCellType = 'tablecell';
11789060b8b0SChristopher Smith    var $inTableHead = true;
1179cef031c1SChristopher Smith    var $currentRow = array('tableheader' => 0, 'tablecell' => 0);
11809060b8b0SChristopher Smith    var $countTableHeadRows = 0;
11810cecf9d5Sandi
11820cecf9d5Sandi    function Doku_Handler_Table(& $CallWriter) {
11830cecf9d5Sandi        $this->CallWriter = & $CallWriter;
11840cecf9d5Sandi    }
11850cecf9d5Sandi
11860cecf9d5Sandi    function writeCall($call) {
11870cecf9d5Sandi        $this->calls[] = $call;
11880cecf9d5Sandi    }
11890cecf9d5Sandi
11900cecf9d5Sandi    // Probably not needed but just in case...
11910cecf9d5Sandi    function writeCalls($calls) {
11920cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
1193f4f02a0fSchris    }
1194f4f02a0fSchris
1195f4f02a0fSchris    function finalise() {
1196f4f02a0fSchris        $last_call = end($this->calls);
1197f4f02a0fSchris        $this->writeCall(array('table_end',array(), $last_call[2]));
1198f4f02a0fSchris
1199f4f02a0fSchris        $this->process();
1200f4f02a0fSchris        $this->CallWriter->finalise();
12013893df8eSChristopher Smith        unset($this->CallWriter);
12020cecf9d5Sandi    }
12030cecf9d5Sandi
12040cecf9d5Sandi    //------------------------------------------------------------------------
12050cecf9d5Sandi    function process() {
12060cecf9d5Sandi        foreach ( $this->calls as $call ) {
12070cecf9d5Sandi            switch ( $call[0] ) {
12080cecf9d5Sandi                case 'table_start':
12090cecf9d5Sandi                    $this->tableStart($call);
12100cecf9d5Sandi                break;
12110cecf9d5Sandi                case 'table_row':
1212aa92c4ccSAdrian Lang                    $this->tableRowClose($call);
12130cecf9d5Sandi                    $this->tableRowOpen(array('tablerow_open',$call[1],$call[2]));
12140cecf9d5Sandi                break;
12150cecf9d5Sandi                case 'tableheader':
12160cecf9d5Sandi                case 'tablecell':
12170cecf9d5Sandi                    $this->tableCell($call);
12180cecf9d5Sandi                break;
12190cecf9d5Sandi                case 'table_end':
1220aa92c4ccSAdrian Lang                    $this->tableRowClose($call);
12210cecf9d5Sandi                    $this->tableEnd($call);
12220cecf9d5Sandi                break;
12230cecf9d5Sandi                default:
12240cecf9d5Sandi                    $this->tableDefault($call);
12250cecf9d5Sandi                break;
12260cecf9d5Sandi            }
12270cecf9d5Sandi        }
12280cecf9d5Sandi        $this->CallWriter->writeCalls($this->tableCalls);
12290cecf9d5Sandi    }
12300cecf9d5Sandi
12310cecf9d5Sandi    function tableStart($call) {
123290df9a4dSAdrian Lang        $this->tableCalls[] = array('table_open',$call[1],$call[2]);
12330cecf9d5Sandi        $this->tableCalls[] = array('tablerow_open',array(),$call[2]);
123444881bd0Shenning.noren        $this->firstCell = true;
12350cecf9d5Sandi    }
12360cecf9d5Sandi
12370cecf9d5Sandi    function tableEnd($call) {
123807c2b1c7SAdrian Lang        $this->tableCalls[] = array('table_close',$call[1],$call[2]);
12390cecf9d5Sandi        $this->finalizeTable();
12400cecf9d5Sandi    }
12410cecf9d5Sandi
12420cecf9d5Sandi    function tableRowOpen($call) {
12430cecf9d5Sandi        $this->tableCalls[] = $call;
12440cecf9d5Sandi        $this->currentCols = 0;
124544881bd0Shenning.noren        $this->firstCell = true;
12460cecf9d5Sandi        $this->lastCellType = 'tablecell';
12470cecf9d5Sandi        $this->maxRows++;
1248cef031c1SChristopher Smith        if ($this->inTableHead) {
1249cef031c1SChristopher Smith            $this->currentRow = array('tablecell' => 0, 'tableheader' => 0);
1250cef031c1SChristopher Smith        }
12510cecf9d5Sandi    }
12520cecf9d5Sandi
12530cecf9d5Sandi    function tableRowClose($call) {
1254cef031c1SChristopher Smith        if ($this->inTableHead && ($this->inTableHead = $this->isTableHeadRow())) {
12559060b8b0SChristopher Smith            $this->countTableHeadRows++;
12569060b8b0SChristopher Smith        }
12570cecf9d5Sandi        // Strip off final cell opening and anything after it
12580cecf9d5Sandi        while ( $discard = array_pop($this->tableCalls ) ) {
12590cecf9d5Sandi
12600cecf9d5Sandi            if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') {
12610cecf9d5Sandi                break;
12620cecf9d5Sandi            }
1263cef031c1SChristopher Smith            if (!empty($this->currentRow[$discard[0]])) {
1264cef031c1SChristopher Smith                $this->currentRow[$discard[0]]--;
1265cef031c1SChristopher Smith            }
12660cecf9d5Sandi        }
1267aa92c4ccSAdrian Lang        $this->tableCalls[] = array('tablerow_close', array(), $call[2]);
12680cecf9d5Sandi
12690cecf9d5Sandi        if ( $this->currentCols > $this->maxCols ) {
12700cecf9d5Sandi            $this->maxCols = $this->currentCols;
12710cecf9d5Sandi        }
12720cecf9d5Sandi    }
12730cecf9d5Sandi
1274cef031c1SChristopher Smith    function isTableHeadRow() {
1275cef031c1SChristopher Smith        $td = $this->currentRow['tablecell'];
1276cef031c1SChristopher Smith        $th = $this->currentRow['tableheader'];
1277cef031c1SChristopher Smith
1278cef031c1SChristopher Smith        if (!$th || $td > 2) return false;
1279cef031c1SChristopher Smith        if (2*$td > $th) return false;
1280cef031c1SChristopher Smith
1281cef031c1SChristopher Smith        return true;
1282cef031c1SChristopher Smith    }
1283cef031c1SChristopher Smith
12840cecf9d5Sandi    function tableCell($call) {
1285cef031c1SChristopher Smith        if ($this->inTableHead) {
1286cef031c1SChristopher Smith            $this->currentRow[$call[0]]++;
12879060b8b0SChristopher Smith        }
12880cecf9d5Sandi        if ( !$this->firstCell ) {
12890cecf9d5Sandi
12900cecf9d5Sandi            // Increase the span
12910cecf9d5Sandi            $lastCall = end($this->tableCalls);
12920cecf9d5Sandi
12930cecf9d5Sandi            // A cell call which follows an open cell means an empty cell so span
12940cecf9d5Sandi            if ( $lastCall[0] == 'tablecell_open' || $lastCall[0] == 'tableheader_open' ) {
12950cecf9d5Sandi                 $this->tableCalls[] = array('colspan',array(),$call[2]);
12960cecf9d5Sandi
12970cecf9d5Sandi            }
12980cecf9d5Sandi
12990cecf9d5Sandi            $this->tableCalls[] = array($this->lastCellType.'_close',array(),$call[2]);
13000ea51e63SMatt Perry            $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
13010cecf9d5Sandi            $this->lastCellType = $call[0];
13020cecf9d5Sandi
13030cecf9d5Sandi        } else {
13040cecf9d5Sandi
13050ea51e63SMatt Perry            $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
13060cecf9d5Sandi            $this->lastCellType = $call[0];
130744881bd0Shenning.noren            $this->firstCell = false;
13080cecf9d5Sandi
13090cecf9d5Sandi        }
13100cecf9d5Sandi
13110cecf9d5Sandi        $this->currentCols++;
13120cecf9d5Sandi    }
13130cecf9d5Sandi
13140cecf9d5Sandi    function tableDefault($call) {
13150cecf9d5Sandi        $this->tableCalls[] = $call;
13160cecf9d5Sandi    }
13170cecf9d5Sandi
13180cecf9d5Sandi    function finalizeTable() {
13190cecf9d5Sandi
13200cecf9d5Sandi        // Add the max cols and rows to the table opening
13210cecf9d5Sandi        if ( $this->tableCalls[0][0] == 'table_open' ) {
13220cecf9d5Sandi            // Adjust to num cols not num col delimeters
13230cecf9d5Sandi            $this->tableCalls[0][1][] = $this->maxCols - 1;
13240cecf9d5Sandi            $this->tableCalls[0][1][] = $this->maxRows;
132590df9a4dSAdrian Lang            $this->tableCalls[0][1][] = array_shift($this->tableCalls[0][1]);
13260cecf9d5Sandi        } else {
13270cecf9d5Sandi            trigger_error('First element in table call list is not table_open');
13280cecf9d5Sandi        }
13290cecf9d5Sandi
13300cecf9d5Sandi        $lastRow = 0;
13310cecf9d5Sandi        $lastCell = 0;
133225b97867Shakan.sandell        $cellKey = array();
13330cecf9d5Sandi        $toDelete = array();
13340cecf9d5Sandi
1335cef031c1SChristopher Smith        // if still in tableheader, then there can be no table header
1336cef031c1SChristopher Smith        // as all rows can't be within <THEAD>
1337cef031c1SChristopher Smith        if ($this->inTableHead) {
1338cef031c1SChristopher Smith            $this->inTableHead = false;
1339cef031c1SChristopher Smith            $this->countTableHeadRows = 0;
1340cef031c1SChristopher Smith        }
1341cef031c1SChristopher Smith
13420cecf9d5Sandi        // Look for the colspan elements and increment the colspan on the
13430cecf9d5Sandi        // previous non-empty opening cell. Once done, delete all the cells
13440cecf9d5Sandi        // that contain colspans
13456606d6fcSAdrian Lang        for ($key = 0 ; $key < count($this->tableCalls) ; ++$key) {
13466606d6fcSAdrian Lang            $call = $this->tableCalls[$key];
13470cecf9d5Sandi
1348aa92c4ccSAdrian Lang            switch ($call[0]) {
13499060b8b0SChristopher Smith                case 'table_open' :
13509060b8b0SChristopher Smith                    if($this->countTableHeadRows) {
13519060b8b0SChristopher Smith                        array_splice($this->tableCalls, $key+1, 0, array(
13529060b8b0SChristopher Smith                              array('tablethead_open', array(), $call[2]))
13539060b8b0SChristopher Smith                        );
13549060b8b0SChristopher Smith                    }
13559060b8b0SChristopher Smith                    break;
13569060b8b0SChristopher Smith
1357aa92c4ccSAdrian Lang                case 'tablerow_open':
13580cecf9d5Sandi
135925b97867Shakan.sandell                    $lastRow++;
136025b97867Shakan.sandell                    $lastCell = 0;
1361aa92c4ccSAdrian Lang                    break;
13620cecf9d5Sandi
1363aa92c4ccSAdrian Lang                case 'tablecell_open':
1364aa92c4ccSAdrian Lang                case 'tableheader_open':
13650cecf9d5Sandi
136625b97867Shakan.sandell                    $lastCell++;
136725b97867Shakan.sandell                    $cellKey[$lastRow][$lastCell] = $key;
1368aa92c4ccSAdrian Lang                    break;
13690cecf9d5Sandi
1370aa92c4ccSAdrian Lang                case 'table_align':
13710cecf9d5Sandi
1372e03b8b2eSAdrian Lang                    $prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));
1373e03b8b2eSAdrian Lang                    $next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));
1374e03b8b2eSAdrian Lang                    // If the cell is empty, align left
1375e03b8b2eSAdrian Lang                    if ($prev && $next) {
1376e03b8b2eSAdrian Lang                        $this->tableCalls[$key-1][1][1] = 'left';
1377e03b8b2eSAdrian Lang
13780cecf9d5Sandi                    // If the previous element was a cell open, align right
1379e03b8b2eSAdrian Lang                    } elseif ($prev) {
13800cecf9d5Sandi                        $this->tableCalls[$key-1][1][1] = 'right';
13810cecf9d5Sandi
1382e03b8b2eSAdrian Lang                    // If the next element is the close of an element, align either center or left
1383e03b8b2eSAdrian Lang                    } elseif ( $next) {
138425b97867Shakan.sandell                        if ( $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] == 'right' ) {
138525b97867Shakan.sandell                            $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'center';
13860cecf9d5Sandi                        } else {
138725b97867Shakan.sandell                            $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'left';
13880cecf9d5Sandi                        }
13890cecf9d5Sandi
13900cecf9d5Sandi                    }
13910cecf9d5Sandi
13920cecf9d5Sandi                    // Now convert the whitespace back to cdata
13930cecf9d5Sandi                    $this->tableCalls[$key][0] = 'cdata';
1394aa92c4ccSAdrian Lang                    break;
13950cecf9d5Sandi
1396aa92c4ccSAdrian Lang                case 'colspan':
13970cecf9d5Sandi
139844881bd0Shenning.noren                    $this->tableCalls[$key-1][1][0] = false;
13990cecf9d5Sandi
140025b97867Shakan.sandell                    for($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) {
14010cecf9d5Sandi
14020cecf9d5Sandi                        if ( $this->tableCalls[$i][0] == 'tablecell_open' || $this->tableCalls[$i][0] == 'tableheader_open' ) {
14030cecf9d5Sandi
140444881bd0Shenning.noren                            if ( false !== $this->tableCalls[$i][1][0] ) {
14050cecf9d5Sandi                                $this->tableCalls[$i][1][0]++;
14060cecf9d5Sandi                                break;
14070cecf9d5Sandi                            }
14080cecf9d5Sandi
14090cecf9d5Sandi                        }
14100cecf9d5Sandi                    }
14110cecf9d5Sandi
14120cecf9d5Sandi                    $toDelete[] = $key-1;
14130cecf9d5Sandi                    $toDelete[] = $key;
14140cecf9d5Sandi                    $toDelete[] = $key+1;
1415aa92c4ccSAdrian Lang                    break;
141625b97867Shakan.sandell
1417aa92c4ccSAdrian Lang                case 'rowspan':
141825b97867Shakan.sandell
141925b97867Shakan.sandell                    if ( $this->tableCalls[$key-1][0] == 'cdata' ) {
142025b97867Shakan.sandell                        // ignore rowspan if previous call was cdata (text mixed with :::) we don't have to check next call as that wont match regex
142125b97867Shakan.sandell                        $this->tableCalls[$key][0] = 'cdata';
142225b97867Shakan.sandell
142325b97867Shakan.sandell                    } else {
142425b97867Shakan.sandell
14256606d6fcSAdrian Lang                        $spanning_cell = null;
14269060b8b0SChristopher Smith
14279060b8b0SChristopher Smith                        // can't cross thead/tbody boundary
14289060b8b0SChristopher Smith                        if (!$this->countTableHeadRows || ($lastRow-1 != $this->countTableHeadRows)) {
142925b97867Shakan.sandell                            for($i = $lastRow-1; $i > 0; $i--) {
143025b97867Shakan.sandell
143125b97867Shakan.sandell                                if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) {
143225b97867Shakan.sandell
14336606d6fcSAdrian Lang                                    if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) {
14346606d6fcSAdrian Lang                                        $spanning_cell = $i;
143525b97867Shakan.sandell                                        break;
143625b97867Shakan.sandell                                    }
143725b97867Shakan.sandell
143825b97867Shakan.sandell                                }
143925b97867Shakan.sandell                            }
14409060b8b0SChristopher Smith                        }
14416606d6fcSAdrian Lang                        if (is_null($spanning_cell)) {
14426606d6fcSAdrian Lang                            // No spanning cell found, so convert this cell to
14436606d6fcSAdrian Lang                            // an empty one to avoid broken tables
14446a7e97d5SGerrit Uitslag                            $this->tableCalls[$key][0] = 'cdata';
14456a7e97d5SGerrit Uitslag                            $this->tableCalls[$key][1][0] = '';
14466606d6fcSAdrian Lang                            continue;
14476606d6fcSAdrian Lang                        }
14486606d6fcSAdrian Lang                        $this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++;
14496606d6fcSAdrian Lang
14506606d6fcSAdrian Lang                        $this->tableCalls[$key-1][1][2] = false;
145125b97867Shakan.sandell
145225b97867Shakan.sandell                        $toDelete[] = $key-1;
145325b97867Shakan.sandell                        $toDelete[] = $key;
145425b97867Shakan.sandell                        $toDelete[] = $key+1;
145525b97867Shakan.sandell                    }
1456aa92c4ccSAdrian Lang                    break;
1457aa92c4ccSAdrian Lang
14586606d6fcSAdrian Lang                case 'tablerow_close':
14596606d6fcSAdrian Lang
14606606d6fcSAdrian Lang                    // Fix broken tables by adding missing cells
14616606d6fcSAdrian Lang                    while (++$lastCell < $this->maxCols) {
14626606d6fcSAdrian Lang                        array_splice($this->tableCalls, $key, 0, array(
14636606d6fcSAdrian Lang                               array('tablecell_open', array(1, null, 1), $call[2]),
14646606d6fcSAdrian Lang                               array('cdata', array(''), $call[2]),
14656606d6fcSAdrian Lang                               array('tablecell_close', array(), $call[2])));
14666606d6fcSAdrian Lang                        $key += 3;
14676606d6fcSAdrian Lang                    }
14686606d6fcSAdrian Lang
14699060b8b0SChristopher Smith                    if($this->countTableHeadRows == $lastRow) {
1470f05a1cc5SGerrit Uitslag                        array_splice($this->tableCalls, $key+1, 0, array(
1471f05a1cc5SGerrit Uitslag                              array('tablethead_close', array(), $call[2])));
1472f05a1cc5SGerrit Uitslag                    }
14736606d6fcSAdrian Lang                    break;
14746606d6fcSAdrian Lang
14750cecf9d5Sandi            }
14760cecf9d5Sandi        }
14770cecf9d5Sandi
14789ab75d9eSAndreas Gohr        // condense cdata
14799ab75d9eSAndreas Gohr        $cnt = count($this->tableCalls);
14809ab75d9eSAndreas Gohr        for( $key = 0; $key < $cnt; $key++){
14819ab75d9eSAndreas Gohr            if($this->tableCalls[$key][0] == 'cdata'){
14829ab75d9eSAndreas Gohr                $ckey = $key;
14839ab75d9eSAndreas Gohr                $key++;
14849ab75d9eSAndreas Gohr                while($this->tableCalls[$key][0] == 'cdata'){
14859ab75d9eSAndreas Gohr                    $this->tableCalls[$ckey][1][0] .= $this->tableCalls[$key][1][0];
14869ab75d9eSAndreas Gohr                    $toDelete[] = $key;
14879ab75d9eSAndreas Gohr                    $key++;
14889ab75d9eSAndreas Gohr                }
14899ab75d9eSAndreas Gohr                continue;
14909ab75d9eSAndreas Gohr            }
14919ab75d9eSAndreas Gohr        }
14929ab75d9eSAndreas Gohr
14930cecf9d5Sandi        foreach ( $toDelete as $delete ) {
14940cecf9d5Sandi            unset($this->tableCalls[$delete]);
14950cecf9d5Sandi        }
14960cecf9d5Sandi        $this->tableCalls = array_values($this->tableCalls);
14970cecf9d5Sandi    }
14980cecf9d5Sandi}
14990cecf9d5Sandi
15000cecf9d5Sandi
15012a27e99aSandi/**
15022a27e99aSandi * Handler for paragraphs
15032a27e99aSandi *
15040b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com>
15052a27e99aSandi */
15060cecf9d5Sandiclass Doku_Handler_Block {
15070cecf9d5Sandi    var $calls = array();
15089569a107SDanny Lin    var $skipEol = false;
150953bfcb59SChristopher Smith    var $inParagraph = false;
15100cecf9d5Sandi
1511af146da0Sandi    // Blocks these should not be inside paragraphs
15120cecf9d5Sandi    var $blockOpen = array(
15130cecf9d5Sandi            'header',
1514df9add72Schris            'listu_open','listo_open','listitem_open','listcontent_open',
1515f05a1cc5SGerrit Uitslag            'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open',
15160cecf9d5Sandi            'quote_open',
151776aa94b7Schris            'code','file','hr','preformatted','rss',
151807f89c3cSAnika Henke            'htmlblock','phpblock',
15199569a107SDanny Lin            'footnote_open',
15200cecf9d5Sandi        );
15210cecf9d5Sandi
15220cecf9d5Sandi    var $blockClose = array(
15230cecf9d5Sandi            'header',
1524df9add72Schris            'listu_close','listo_close','listitem_close','listcontent_close',
1525f05a1cc5SGerrit Uitslag            'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close',
15260cecf9d5Sandi            'quote_close',
152776aa94b7Schris            'code','file','hr','preformatted','rss',
152807f89c3cSAnika Henke            'htmlblock','phpblock',
15299569a107SDanny Lin            'footnote_close',
15300cecf9d5Sandi        );
15310cecf9d5Sandi
1532af146da0Sandi    // Stacks can contain paragraphs
15330cecf9d5Sandi    var $stackOpen = array(
15349569a107SDanny Lin        'section_open',
15350cecf9d5Sandi        );
15360cecf9d5Sandi
15370cecf9d5Sandi    var $stackClose = array(
15389569a107SDanny Lin        'section_close',
15390cecf9d5Sandi        );
15400cecf9d5Sandi
1541af146da0Sandi
1542af146da0Sandi    /**
1543af146da0Sandi     * Constructor. Adds loaded syntax plugins to the block and stack
1544af146da0Sandi     * arrays
1545af146da0Sandi     *
1546af146da0Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1547af146da0Sandi     */
1548af146da0Sandi    function Doku_Handler_Block(){
1549af146da0Sandi        global $DOKU_PLUGINS;
1550af146da0Sandi        //check if syntax plugins were loaded
155103c4aec3Schris        if(empty($DOKU_PLUGINS['syntax'])) return;
1552af146da0Sandi        foreach($DOKU_PLUGINS['syntax'] as $n => $p){
1553af146da0Sandi            $ptype = $p->getPType();
1554af146da0Sandi            if($ptype == 'block'){
1555af146da0Sandi                $this->blockOpen[]  = 'plugin_'.$n;
1556af146da0Sandi                $this->blockClose[] = 'plugin_'.$n;
1557af146da0Sandi            }elseif($ptype == 'stack'){
1558af146da0Sandi                $this->stackOpen[]  = 'plugin_'.$n;
1559af146da0Sandi                $this->stackClose[] = 'plugin_'.$n;
1560af146da0Sandi            }
1561af146da0Sandi        }
1562af146da0Sandi    }
1563af146da0Sandi
1564b5a0b131SDanny Lin    function openParagraph($pos){
15659569a107SDanny Lin        if ($this->inParagraph) return;
1566b5a0b131SDanny Lin        $this->calls[] = array('p_open',array(), $pos);
1567b5a0b131SDanny Lin        $this->inParagraph = true;
15689569a107SDanny Lin        $this->skipEol = true;
1569b5a0b131SDanny Lin    }
1570b5a0b131SDanny Lin
15712a27e99aSandi    /**
15722a27e99aSandi     * Close a paragraph if needed
15732a27e99aSandi     *
15742a27e99aSandi     * This function makes sure there are no empty paragraphs on the stack
15752a27e99aSandi     *
15762a27e99aSandi     * @author Andreas Gohr <andi@splitbrain.org>
15772a27e99aSandi     */
1578506ae684Sandi    function closeParagraph($pos){
15799569a107SDanny Lin        if (!$this->inParagraph) return;
1580506ae684Sandi        // look back if there was any content - we don't want empty paragraphs
1581506ae684Sandi        $content = '';
1582faba9a35SAndreas Gohr        $ccount = count($this->calls);
1583faba9a35SAndreas Gohr        for($i=$ccount-1; $i>=0; $i--){
1584506ae684Sandi            if($this->calls[$i][0] == 'p_open'){
1585506ae684Sandi                break;
1586506ae684Sandi            }elseif($this->calls[$i][0] == 'cdata'){
1587506ae684Sandi                $content .= $this->calls[$i][1][0];
1588506ae684Sandi            }else{
1589506ae684Sandi                $content = 'found markup';
1590506ae684Sandi                break;
1591506ae684Sandi            }
1592506ae684Sandi        }
1593506ae684Sandi
1594506ae684Sandi        if(trim($content)==''){
1595506ae684Sandi            //remove the whole paragraph
1596a86cc527SAndreas Gohr            //array_splice($this->calls,$i); // <- this is much slower than the loop below
1597d8f7a7f3SAndreas Gohr            for($x=$ccount; $x>$i; $x--) array_pop($this->calls);
1598506ae684Sandi        }else{
15999569a107SDanny Lin            // remove ending linebreaks in the paragraph
16009569a107SDanny Lin            $i=count($this->calls)-1;
16019569a107SDanny Lin            if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL);
1602506ae684Sandi            $this->calls[] = array('p_close',array(), $pos);
1603506ae684Sandi        }
1604e1c10e4dSchris
160544881bd0Shenning.noren        $this->inParagraph = false;
16069569a107SDanny Lin        $this->skipEol = true;
16070cecf9d5Sandi    }
160841624b31SChris Smith
160941624b31SChris Smith    function addCall($call) {
161041624b31SChris Smith        $key = count($this->calls);
161141624b31SChris Smith        if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
161241624b31SChris Smith            $this->calls[$key-1][1][0] .= $call[1][0];
161341624b31SChris Smith        } else {
161441624b31SChris Smith            $this->calls[] = $call;
161541624b31SChris Smith        }
161641624b31SChris Smith    }
16179569a107SDanny Lin
16189569a107SDanny Lin    // simple version of addCall, without checking cdata
16199569a107SDanny Lin    function storeCall($call) {
16209569a107SDanny Lin        $this->calls[] = $call;
16219569a107SDanny Lin    }
16229569a107SDanny Lin
16239569a107SDanny Lin    /**
16249569a107SDanny Lin     * Processes the whole instruction stack to open and close paragraphs
16259569a107SDanny Lin     *
16269569a107SDanny Lin     * @author Harry Fuecks <hfuecks@gmail.com>
16279569a107SDanny Lin     * @author Andreas Gohr <andi@splitbrain.org>
16289569a107SDanny Lin     */
16299569a107SDanny Lin    function process($calls) {
16309569a107SDanny Lin        // open first paragraph
16319569a107SDanny Lin        $this->openParagraph(0);
16329569a107SDanny Lin        foreach ( $calls as $key => $call ) {
16339569a107SDanny Lin            $cname = $call[0];
16349569a107SDanny Lin            if ($cname == 'plugin') {
16359569a107SDanny Lin                $cname='plugin_'.$call[1][0];
16369569a107SDanny Lin                $plugin = true;
16379569a107SDanny Lin                $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));
16389569a107SDanny Lin                $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));
16399569a107SDanny Lin            } else {
16409569a107SDanny Lin                $plugin = false;
16419569a107SDanny Lin            }
16429569a107SDanny Lin            /* stack */
16439569a107SDanny Lin            if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) {
16449569a107SDanny Lin                $this->closeParagraph($call[2]);
16459569a107SDanny Lin                $this->storeCall($call);
16469569a107SDanny Lin                $this->openParagraph($call[2]);
16479569a107SDanny Lin                continue;
16489569a107SDanny Lin            }
16499569a107SDanny Lin            if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) {
16509569a107SDanny Lin                $this->closeParagraph($call[2]);
16519569a107SDanny Lin                $this->storeCall($call);
16529569a107SDanny Lin                $this->openParagraph($call[2]);
16539569a107SDanny Lin                continue;
16549569a107SDanny Lin            }
16559569a107SDanny Lin            /* block */
16569569a107SDanny Lin            // If it's a substition it opens and closes at the same call.
16579569a107SDanny Lin            // To make sure next paragraph is correctly started, let close go first.
16589569a107SDanny Lin            if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
16599569a107SDanny Lin                $this->closeParagraph($call[2]);
16609569a107SDanny Lin                $this->storeCall($call);
16619569a107SDanny Lin                $this->openParagraph($call[2]);
16629569a107SDanny Lin                continue;
16639569a107SDanny Lin            }
16649569a107SDanny Lin            if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) {
16659569a107SDanny Lin                $this->closeParagraph($call[2]);
16669569a107SDanny Lin                $this->storeCall($call);
16679569a107SDanny Lin                continue;
16689569a107SDanny Lin            }
16699569a107SDanny Lin            /* eol */
16709569a107SDanny Lin            if ( $cname == 'eol' ) {
16719569a107SDanny Lin                // Check this isn't an eol instruction to skip...
16729569a107SDanny Lin                if ( !$this->skipEol ) {
16739569a107SDanny Lin                    // Next is EOL => double eol => mark as paragraph
16749569a107SDanny Lin                    if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
16759569a107SDanny Lin                        $this->closeParagraph($call[2]);
16769569a107SDanny Lin                        $this->openParagraph($call[2]);
16779569a107SDanny Lin                    } else {
16789569a107SDanny Lin                        //if this is just a single eol make a space from it
16799569a107SDanny Lin                        $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
16809569a107SDanny Lin                    }
16819569a107SDanny Lin                }
16829569a107SDanny Lin                continue;
16839569a107SDanny Lin            }
16849569a107SDanny Lin            /* normal */
16859569a107SDanny Lin            $this->addCall($call);
16869569a107SDanny Lin            $this->skipEol = false;
16879569a107SDanny Lin        }
16889569a107SDanny Lin        // close last paragraph
16899569a107SDanny Lin        $call = end($this->calls);
16909569a107SDanny Lin        $this->closeParagraph($call[2]);
16919569a107SDanny Lin        return $this->calls;
16929569a107SDanny Lin    }
16930cecf9d5Sandi}
16942a27e99aSandi
1695e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1696