xref: /dokuwiki/inc/parser/handler.php (revision 10bcc8aaa0f8014e1c5e2d059ea674fc0063233d)
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);
7445d5ad75SGerrit Uitslag        $plugin = plugin_load('syntax',$pluginname);
75a46d0d65SAndreas Gohr        if($plugin != null){
76f02a7d06Schris            $data = $plugin->handle($match, $state, $pos, $this);
77ee20e7d1Sandi        }
7813ecfb18SChris Smith        if ($data !== false) {
7982d61635Spierre.spring            $this->addPluginCall($pluginname,$data,$state,$pos,$match);
8013ecfb18SChris Smith        }
8144881bd0Shenning.noren        return true;
82ee20e7d1Sandi    }
830cecf9d5Sandi
840cecf9d5Sandi    function base($match, $state, $pos) {
850cecf9d5Sandi        switch ( $state ) {
860cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
87433bef32Sandi                $this->_addCall('cdata',array($match), $pos);
8844881bd0Shenning.noren                return true;
890cecf9d5Sandi            break;
900cecf9d5Sandi        }
910cecf9d5Sandi    }
920cecf9d5Sandi
930cecf9d5Sandi    function header($match, $state, $pos) {
94d7e8115fSAndreas Gohr        // get level and title
95a4a2d4cfSAndreas Gohr        $title = trim($match);
96a4a2d4cfSAndreas Gohr        $level = 7 - strspn($title,'=');
97d7e8115fSAndreas Gohr        if($level < 1) $level = 1;
98a4a2d4cfSAndreas Gohr        $title = trim($title,'=');
99a4a2d4cfSAndreas Gohr        $title = trim($title);
1000cecf9d5Sandi
101e1c10e4dSchris        if ($this->status['section']) $this->_addCall('section_close',array(),$pos);
102e1c10e4dSchris
103433bef32Sandi        $this->_addCall('header',array($title,$level,$pos), $pos);
104e1c10e4dSchris
105e1c10e4dSchris        $this->_addCall('section_open',array($level),$pos);
10644881bd0Shenning.noren        $this->status['section'] = true;
10744881bd0Shenning.noren        return true;
1080cecf9d5Sandi    }
1090cecf9d5Sandi
1100cecf9d5Sandi    function notoc($match, $state, $pos) {
111e41c4da9SAndreas Gohr        $this->_addCall('notoc',array(),$pos);
11244881bd0Shenning.noren        return true;
1130cecf9d5Sandi    }
1140cecf9d5Sandi
1159dc2c2afSandi    function nocache($match, $state, $pos) {
1169dc2c2afSandi        $this->_addCall('nocache',array(),$pos);
11744881bd0Shenning.noren        return true;
1189dc2c2afSandi    }
1199dc2c2afSandi
1200cecf9d5Sandi    function linebreak($match, $state, $pos) {
121433bef32Sandi        $this->_addCall('linebreak',array(),$pos);
12244881bd0Shenning.noren        return true;
1230cecf9d5Sandi    }
1240cecf9d5Sandi
1250cecf9d5Sandi    function eol($match, $state, $pos) {
126433bef32Sandi        $this->_addCall('eol',array(),$pos);
12744881bd0Shenning.noren        return true;
1280cecf9d5Sandi    }
1290cecf9d5Sandi
1300cecf9d5Sandi    function hr($match, $state, $pos) {
131433bef32Sandi        $this->_addCall('hr',array(),$pos);
13244881bd0Shenning.noren        return true;
1330cecf9d5Sandi    }
1340cecf9d5Sandi
135433bef32Sandi    function _nestingTag($match, $state, $pos, $name) {
1360cecf9d5Sandi        switch ( $state ) {
1370cecf9d5Sandi            case DOKU_LEXER_ENTER:
138433bef32Sandi                $this->_addCall($name.'_open', array(), $pos);
1390cecf9d5Sandi            break;
1400cecf9d5Sandi            case DOKU_LEXER_EXIT:
141433bef32Sandi                $this->_addCall($name.'_close', array(), $pos);
1420cecf9d5Sandi            break;
1430cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
144433bef32Sandi                $this->_addCall('cdata',array($match), $pos);
1450cecf9d5Sandi            break;
1460cecf9d5Sandi        }
1470cecf9d5Sandi    }
1480cecf9d5Sandi
1490cecf9d5Sandi    function strong($match, $state, $pos) {
150433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'strong');
15144881bd0Shenning.noren        return true;
1520cecf9d5Sandi    }
1530cecf9d5Sandi
1540cecf9d5Sandi    function emphasis($match, $state, $pos) {
155433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'emphasis');
15644881bd0Shenning.noren        return true;
1570cecf9d5Sandi    }
1580cecf9d5Sandi
1590cecf9d5Sandi    function underline($match, $state, $pos) {
160433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'underline');
16144881bd0Shenning.noren        return true;
1620cecf9d5Sandi    }
1630cecf9d5Sandi
1640cecf9d5Sandi    function monospace($match, $state, $pos) {
165433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'monospace');
16644881bd0Shenning.noren        return true;
1670cecf9d5Sandi    }
1680cecf9d5Sandi
1690cecf9d5Sandi    function subscript($match, $state, $pos) {
170433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'subscript');
17144881bd0Shenning.noren        return true;
1720cecf9d5Sandi    }
1730cecf9d5Sandi
1740cecf9d5Sandi    function superscript($match, $state, $pos) {
175433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'superscript');
17644881bd0Shenning.noren        return true;
1770cecf9d5Sandi    }
1780cecf9d5Sandi
1790cecf9d5Sandi    function deleted($match, $state, $pos) {
180433bef32Sandi        $this->_nestingTag($match, $state, $pos, 'deleted');
18144881bd0Shenning.noren        return true;
1820cecf9d5Sandi    }
1830cecf9d5Sandi
1840cecf9d5Sandi
1850cecf9d5Sandi    function footnote($match, $state, $pos) {
1865587e44cSchris//        $this->_nestingTag($match, $state, $pos, 'footnote');
187742c66f8Schris        if (!isset($this->_footnote)) $this->_footnote = false;
1882fe7363dSchris
1895587e44cSchris        switch ( $state ) {
1905587e44cSchris            case DOKU_LEXER_ENTER:
1912fe7363dSchris                // footnotes can not be nested - however due to limitations in lexer it can't be prevented
1922fe7363dSchris                // we will still enter a new footnote mode, we just do nothing
193742c66f8Schris                if ($this->_footnote) {
1942fe7363dSchris                    $this->_addCall('cdata',array($match), $pos);
1952fe7363dSchris                    break;
1962fe7363dSchris                }
1972fe7363dSchris
198742c66f8Schris                $this->_footnote = true;
1992fe7363dSchris
20067f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Nest($this->CallWriter,'footnote_close');
2015587e44cSchris                $this->CallWriter = & $ReWriter;
2024a26ad85Schris                $this->_addCall('footnote_open', array(), $pos);
2035587e44cSchris            break;
2045587e44cSchris            case DOKU_LEXER_EXIT:
2052fe7363dSchris                // check whether we have already exitted the footnote mode, can happen if the modes were nested
206742c66f8Schris                if (!$this->_footnote) {
2072fe7363dSchris                    $this->_addCall('cdata',array($match), $pos);
2082fe7363dSchris                    break;
2092fe7363dSchris                }
2102fe7363dSchris
211742c66f8Schris                $this->_footnote = false;
2122fe7363dSchris
2135587e44cSchris                $this->_addCall('footnote_close', array(), $pos);
2145587e44cSchris                $this->CallWriter->process();
2155587e44cSchris                $ReWriter = & $this->CallWriter;
2165587e44cSchris                $this->CallWriter = & $ReWriter->CallWriter;
2175587e44cSchris            break;
2185587e44cSchris            case DOKU_LEXER_UNMATCHED:
2195587e44cSchris                $this->_addCall('cdata', array($match), $pos);
2205587e44cSchris            break;
2215587e44cSchris        }
22244881bd0Shenning.noren        return true;
2230cecf9d5Sandi    }
2240cecf9d5Sandi
2250cecf9d5Sandi    function listblock($match, $state, $pos) {
2260cecf9d5Sandi        switch ( $state ) {
2270cecf9d5Sandi            case DOKU_LEXER_ENTER:
22867f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_List($this->CallWriter);
2290cecf9d5Sandi                $this->CallWriter = & $ReWriter;
230433bef32Sandi                $this->_addCall('list_open', array($match), $pos);
2310cecf9d5Sandi            break;
2320cecf9d5Sandi            case DOKU_LEXER_EXIT:
233433bef32Sandi                $this->_addCall('list_close', array(), $pos);
2340cecf9d5Sandi                $this->CallWriter->process();
2350cecf9d5Sandi                $ReWriter = & $this->CallWriter;
2360cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
2370cecf9d5Sandi            break;
2380cecf9d5Sandi            case DOKU_LEXER_MATCHED:
239433bef32Sandi                $this->_addCall('list_item', array($match), $pos);
2400cecf9d5Sandi            break;
2410cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
242433bef32Sandi                $this->_addCall('cdata', array($match), $pos);
2430cecf9d5Sandi            break;
2440cecf9d5Sandi        }
24544881bd0Shenning.noren        return true;
2460cecf9d5Sandi    }
2470cecf9d5Sandi
2480cecf9d5Sandi    function unformatted($match, $state, $pos) {
2490cecf9d5Sandi        if ( $state == DOKU_LEXER_UNMATCHED ) {
250433bef32Sandi            $this->_addCall('unformatted',array($match), $pos);
2510cecf9d5Sandi        }
25244881bd0Shenning.noren        return true;
2530cecf9d5Sandi    }
2540cecf9d5Sandi
2550cecf9d5Sandi    function php($match, $state, $pos) {
256df9add72Schris        global $conf;
2570cecf9d5Sandi        if ( $state == DOKU_LEXER_UNMATCHED ) {
258433bef32Sandi            $this->_addCall('php',array($match), $pos);
2590cecf9d5Sandi        }
26044881bd0Shenning.noren        return true;
2610cecf9d5Sandi    }
2620cecf9d5Sandi
26307f89c3cSAnika Henke    function phpblock($match, $state, $pos) {
26407f89c3cSAnika Henke        global $conf;
26507f89c3cSAnika Henke        if ( $state == DOKU_LEXER_UNMATCHED ) {
26607f89c3cSAnika Henke            $this->_addCall('phpblock',array($match), $pos);
26707f89c3cSAnika Henke        }
26807f89c3cSAnika Henke        return true;
26907f89c3cSAnika Henke    }
27007f89c3cSAnika Henke
2710cecf9d5Sandi    function html($match, $state, $pos) {
272df9add72Schris        global $conf;
2730cecf9d5Sandi        if ( $state == DOKU_LEXER_UNMATCHED ) {
274433bef32Sandi            $this->_addCall('html',array($match), $pos);
2750cecf9d5Sandi        }
27644881bd0Shenning.noren        return true;
2770cecf9d5Sandi    }
2780cecf9d5Sandi
27907f89c3cSAnika Henke    function htmlblock($match, $state, $pos) {
28007f89c3cSAnika Henke        global $conf;
28107f89c3cSAnika Henke        if ( $state == DOKU_LEXER_UNMATCHED ) {
28207f89c3cSAnika Henke            $this->_addCall('htmlblock',array($match), $pos);
28307f89c3cSAnika Henke        }
28407f89c3cSAnika Henke        return true;
28507f89c3cSAnika Henke    }
28607f89c3cSAnika Henke
2870cecf9d5Sandi    function preformatted($match, $state, $pos) {
2880cecf9d5Sandi        switch ( $state ) {
2890cecf9d5Sandi            case DOKU_LEXER_ENTER:
29067f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Preformatted($this->CallWriter);
2910cecf9d5Sandi                $this->CallWriter = & $ReWriter;
292433bef32Sandi                $this->_addCall('preformatted_start',array(), $pos);
2930cecf9d5Sandi            break;
2940cecf9d5Sandi            case DOKU_LEXER_EXIT:
295433bef32Sandi                $this->_addCall('preformatted_end',array(), $pos);
2960cecf9d5Sandi                $this->CallWriter->process();
2970cecf9d5Sandi                $ReWriter = & $this->CallWriter;
2980cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
2990cecf9d5Sandi            break;
3000cecf9d5Sandi            case DOKU_LEXER_MATCHED:
301433bef32Sandi                $this->_addCall('preformatted_newline',array(), $pos);
3020cecf9d5Sandi            break;
3030cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
304433bef32Sandi                $this->_addCall('preformatted_content',array($match), $pos);
3050cecf9d5Sandi            break;
3060cecf9d5Sandi        }
3070cecf9d5Sandi
30844881bd0Shenning.noren        return true;
3090cecf9d5Sandi    }
3100cecf9d5Sandi
3110cecf9d5Sandi    function quote($match, $state, $pos) {
3120cecf9d5Sandi
3130cecf9d5Sandi        switch ( $state ) {
3140cecf9d5Sandi
3150cecf9d5Sandi            case DOKU_LEXER_ENTER:
31667f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Quote($this->CallWriter);
3170cecf9d5Sandi                $this->CallWriter = & $ReWriter;
318433bef32Sandi                $this->_addCall('quote_start',array($match), $pos);
3190cecf9d5Sandi            break;
3200cecf9d5Sandi
3210cecf9d5Sandi            case DOKU_LEXER_EXIT:
322433bef32Sandi                $this->_addCall('quote_end',array(), $pos);
3230cecf9d5Sandi                $this->CallWriter->process();
3240cecf9d5Sandi                $ReWriter = & $this->CallWriter;
3250cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
3260cecf9d5Sandi            break;
3270cecf9d5Sandi
3280cecf9d5Sandi            case DOKU_LEXER_MATCHED:
329433bef32Sandi                $this->_addCall('quote_newline',array($match), $pos);
3300cecf9d5Sandi            break;
3310cecf9d5Sandi
3320cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
333433bef32Sandi                $this->_addCall('cdata',array($match), $pos);
3340cecf9d5Sandi            break;
3350cecf9d5Sandi
3360cecf9d5Sandi        }
3370cecf9d5Sandi
33844881bd0Shenning.noren        return true;
3390cecf9d5Sandi    }
3400cecf9d5Sandi
3413d491f75SAndreas Gohr    function file($match, $state, $pos) {
3423d491f75SAndreas Gohr        return $this->code($match, $state, $pos, 'file');
3433d491f75SAndreas Gohr    }
3443d491f75SAndreas Gohr
3453d491f75SAndreas Gohr    function code($match, $state, $pos, $type='code') {
3463d491f75SAndreas Gohr        if ( $state == DOKU_LEXER_UNMATCHED ) {
3474b7f9e70STom N Harris            $matches = explode('>',$match,2);
3483d491f75SAndreas Gohr
3490139312bSAdrian Lang            $param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY);
3500139312bSAdrian Lang            while(count($param) < 2) array_push($param, null);
3510139312bSAdrian Lang
3520139312bSAdrian Lang            // We shortcut html here.
3530139312bSAdrian Lang            if ($param[0] == 'html') $param[0] = 'html4strict';
3540139312bSAdrian Lang            if ($param[0] == '-') $param[0] = null;
3550139312bSAdrian Lang            array_unshift($param, $matches[1]);
3560139312bSAdrian Lang
3570139312bSAdrian Lang            $this->_addCall($type, $param, $pos);
3580cecf9d5Sandi        }
35944881bd0Shenning.noren        return true;
3600cecf9d5Sandi    }
3610cecf9d5Sandi
3620cecf9d5Sandi    function acronym($match, $state, $pos) {
363433bef32Sandi        $this->_addCall('acronym',array($match), $pos);
36444881bd0Shenning.noren        return true;
3650cecf9d5Sandi    }
3660cecf9d5Sandi
3670cecf9d5Sandi    function smiley($match, $state, $pos) {
368433bef32Sandi        $this->_addCall('smiley',array($match), $pos);
36944881bd0Shenning.noren        return true;
3700cecf9d5Sandi    }
3710cecf9d5Sandi
3720cecf9d5Sandi    function wordblock($match, $state, $pos) {
373433bef32Sandi        $this->_addCall('wordblock',array($match), $pos);
37444881bd0Shenning.noren        return true;
3750cecf9d5Sandi    }
3760cecf9d5Sandi
3770cecf9d5Sandi    function entity($match, $state, $pos) {
378433bef32Sandi        $this->_addCall('entity',array($match), $pos);
37944881bd0Shenning.noren        return true;
3800cecf9d5Sandi    }
3810cecf9d5Sandi
3820cecf9d5Sandi    function multiplyentity($match, $state, $pos) {
3830cecf9d5Sandi        preg_match_all('/\d+/',$match,$matches);
384433bef32Sandi        $this->_addCall('multiplyentity',array($matches[0][0],$matches[0][1]), $pos);
38544881bd0Shenning.noren        return true;
3860cecf9d5Sandi    }
3870cecf9d5Sandi
3880cecf9d5Sandi    function singlequoteopening($match, $state, $pos) {
389433bef32Sandi        $this->_addCall('singlequoteopening',array(), $pos);
39044881bd0Shenning.noren        return true;
3910cecf9d5Sandi    }
3920cecf9d5Sandi
3930cecf9d5Sandi    function singlequoteclosing($match, $state, $pos) {
394433bef32Sandi        $this->_addCall('singlequoteclosing',array(), $pos);
39544881bd0Shenning.noren        return true;
3960cecf9d5Sandi    }
3970cecf9d5Sandi
39857d757d1SAndreas Gohr    function apostrophe($match, $state, $pos) {
39957d757d1SAndreas Gohr        $this->_addCall('apostrophe',array(), $pos);
40057d757d1SAndreas Gohr        return true;
40157d757d1SAndreas Gohr    }
40257d757d1SAndreas Gohr
4030cecf9d5Sandi    function doublequoteopening($match, $state, $pos) {
404433bef32Sandi        $this->_addCall('doublequoteopening',array(), $pos);
405e950d12fSChristopher Smith        $this->status['doublequote']++;
40644881bd0Shenning.noren        return true;
4070cecf9d5Sandi    }
4080cecf9d5Sandi
4090cecf9d5Sandi    function doublequoteclosing($match, $state, $pos) {
410e950d12fSChristopher Smith        if ($this->status['doublequote'] <= 0) {
411e950d12fSChristopher Smith            $this->doublequoteopening($match, $state, $pos);
412e950d12fSChristopher Smith        } else {
413433bef32Sandi            $this->_addCall('doublequoteclosing',array(), $pos);
414e950d12fSChristopher Smith            $this->status['doublequote'] = max(0, --$this->status['doublequote']);
415e950d12fSChristopher Smith        }
41644881bd0Shenning.noren        return true;
4170cecf9d5Sandi    }
4180cecf9d5Sandi
4190cecf9d5Sandi    function camelcaselink($match, $state, $pos) {
420433bef32Sandi        $this->_addCall('camelcaselink',array($match), $pos);
42144881bd0Shenning.noren        return true;
4220cecf9d5Sandi    }
4230cecf9d5Sandi
4240cecf9d5Sandi    /*
4250cecf9d5Sandi    */
4260cecf9d5Sandi    function internallink($match, $state, $pos) {
4270cecf9d5Sandi        // Strip the opening and closing markup
4280cecf9d5Sandi        $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);
4290cecf9d5Sandi
4300cecf9d5Sandi        // Split title from URL
4314b7f9e70STom N Harris        $link = explode('|',$link,2);
4320cecf9d5Sandi        if ( !isset($link[1]) ) {
4330ea51e63SMatt Perry            $link[1] = null;
4340cecf9d5Sandi        } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) {
4355578eb8fSandi            // If the title is an image, convert it to an array containing the image details
436b625487dSandi            $link[1] = Doku_Handler_Parse_Media($link[1]);
4370cecf9d5Sandi        }
4380b7c14c2Sandi        $link[0] = trim($link[0]);
4390cecf9d5Sandi
4400e1c636eSandi        //decide which kind of link it is
4410e1c636eSandi
442e08dda3fSAndreas Gohr        if ( preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link[0]) ) {
4430e1c636eSandi            // Interwiki
4444b7f9e70STom N Harris            $interwiki = explode('>',$link[0],2);
445433bef32Sandi            $this->_addCall(
4460cecf9d5Sandi                'interwikilink',
4470cecf9d5Sandi                array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]),
4480cecf9d5Sandi                $pos
4490cecf9d5Sandi                );
45015f1b77cSAndreas Gohr        }elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) {
4510e1c636eSandi            // Windows Share
452433bef32Sandi            $this->_addCall(
4530cecf9d5Sandi                'windowssharelink',
4540cecf9d5Sandi                array($link[0],$link[1]),
4550cecf9d5Sandi                $pos
4560cecf9d5Sandi                );
4574468cb4cSAndreas Gohr        }elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) {
4580e1c636eSandi            // external link (accepts all protocols)
459433bef32Sandi            $this->_addCall(
4600cecf9d5Sandi                    'externallink',
4610cecf9d5Sandi                    array($link[0],$link[1]),
4620cecf9d5Sandi                    $pos
4630cecf9d5Sandi                    );
4640a1d30bfSchris        }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) {
4650a1d30bfSchris            // E-Mail (pattern above is defined in inc/mail.php)
466a6755281Sandi            $this->_addCall(
467a6755281Sandi                'emaillink',
468a6755281Sandi                array($link[0],$link[1]),
469a6755281Sandi                $pos
470a6755281Sandi                );
4710b7c14c2Sandi        }elseif ( preg_match('!^#.+!',$link[0]) ){
4720b7c14c2Sandi            // local link
4730b7c14c2Sandi            $this->_addCall(
4740b7c14c2Sandi                'locallink',
4750b7c14c2Sandi                array(substr($link[0],1),$link[1]),
4760b7c14c2Sandi                $pos
4770b7c14c2Sandi                );
4780e1c636eSandi        }else{
4790e1c636eSandi            // internal link
480433bef32Sandi            $this->_addCall(
4810e1c636eSandi                'internallink',
4820e1c636eSandi                array($link[0],$link[1]),
4830e1c636eSandi                $pos
4840e1c636eSandi                );
4850cecf9d5Sandi        }
4860e1c636eSandi
48744881bd0Shenning.noren        return true;
4880cecf9d5Sandi    }
4890cecf9d5Sandi
4900cecf9d5Sandi    function filelink($match, $state, $pos) {
4910ea51e63SMatt Perry        $this->_addCall('filelink',array($match, null), $pos);
49244881bd0Shenning.noren        return true;
4930cecf9d5Sandi    }
4940cecf9d5Sandi
4950cecf9d5Sandi    function windowssharelink($match, $state, $pos) {
4960ea51e63SMatt Perry        $this->_addCall('windowssharelink',array($match, null), $pos);
49744881bd0Shenning.noren        return true;
4980cecf9d5Sandi    }
4990cecf9d5Sandi
5000cecf9d5Sandi    function media($match, $state, $pos) {
5010cecf9d5Sandi        $p = Doku_Handler_Parse_Media($match);
5020cecf9d5Sandi
503433bef32Sandi        $this->_addCall(
5040cecf9d5Sandi              $p['type'],
505dc673a5bSjoe.lapp              array($p['src'], $p['title'], $p['align'], $p['width'],
506dc673a5bSjoe.lapp                     $p['height'], $p['cache'], $p['linking']),
5070cecf9d5Sandi              $pos
5080cecf9d5Sandi             );
50944881bd0Shenning.noren        return true;
5100cecf9d5Sandi    }
5110cecf9d5Sandi
512b625487dSandi    function rss($match, $state, $pos) {
513b625487dSandi        $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match);
5143db95becSAndreas Gohr
5153db95becSAndreas Gohr        // get params
5163db95becSAndreas Gohr        list($link,$params) = explode(' ',$link,2);
5173db95becSAndreas Gohr
5183db95becSAndreas Gohr        $p = array();
5193db95becSAndreas Gohr        if(preg_match('/\b(\d+)\b/',$params,$match)){
5203db95becSAndreas Gohr            $p['max'] = $match[1];
5213db95becSAndreas Gohr        }else{
5223db95becSAndreas Gohr            $p['max'] = 8;
5233db95becSAndreas Gohr        }
5243db95becSAndreas Gohr        $p['reverse'] = (preg_match('/rev/',$params));
5253db95becSAndreas Gohr        $p['author']  = (preg_match('/\b(by|author)/',$params));
5263db95becSAndreas Gohr        $p['date']    = (preg_match('/\b(date)/',$params));
5273db95becSAndreas Gohr        $p['details'] = (preg_match('/\b(desc|detail)/',$params));
5283db95becSAndreas Gohr
5290a69dff7Schris        if (preg_match('/\b(\d+)([dhm])\b/',$params,$match)) {
5300a69dff7Schris            $period = array('d' => 86400, 'h' => 3600, 'm' => 60);
5310a69dff7Schris            $p['refresh'] = max(600,$match[1]*$period[$match[2]]);  // n * period in seconds, minimum 10 minutes
5320a69dff7Schris        } else {
5330a69dff7Schris            $p['refresh'] = 14400;   // default to 4 hours
5340a69dff7Schris        }
5350a69dff7Schris
5363db95becSAndreas Gohr        $this->_addCall('rss',array($link,$p),$pos);
53744881bd0Shenning.noren        return true;
538b625487dSandi    }
539b625487dSandi
5400cecf9d5Sandi    function externallink($match, $state, $pos) {
541da9f31c5SAndreas Gohr        $url   = $match;
542da9f31c5SAndreas Gohr        $title = null;
5430cecf9d5Sandi
544da9f31c5SAndreas Gohr        // add protocol on simple short URLs
545da9f31c5SAndreas Gohr        if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')){
546da9f31c5SAndreas Gohr            $title = $url;
547da9f31c5SAndreas Gohr            $url   = 'ftp://'.$url;
548da9f31c5SAndreas Gohr        }
549da9f31c5SAndreas Gohr        if(substr($url,0,3) == 'www' && (substr($url,0,7) != 'http://')){
550da9f31c5SAndreas Gohr            $title = $url;
551da9f31c5SAndreas Gohr            $url = 'http://'.$url;
552da9f31c5SAndreas Gohr        }
553da9f31c5SAndreas Gohr
554da9f31c5SAndreas Gohr        $this->_addCall('externallink',array($url, $title), $pos);
55544881bd0Shenning.noren        return true;
5560cecf9d5Sandi    }
5570cecf9d5Sandi
55871352defSandi    function emaillink($match, $state, $pos) {
5590cecf9d5Sandi        $email = preg_replace(array('/^</','/>$/'),'',$match);
5600ea51e63SMatt Perry        $this->_addCall('emaillink',array($email, null), $pos);
56144881bd0Shenning.noren        return true;
5620cecf9d5Sandi    }
5630cecf9d5Sandi
5640cecf9d5Sandi    function table($match, $state, $pos) {
5650cecf9d5Sandi        switch ( $state ) {
5660cecf9d5Sandi
5670cecf9d5Sandi            case DOKU_LEXER_ENTER:
5680cecf9d5Sandi
56967f9913dSAndreas Gohr                $ReWriter = new Doku_Handler_Table($this->CallWriter);
5700cecf9d5Sandi                $this->CallWriter = & $ReWriter;
5710cecf9d5Sandi
57290df9a4dSAdrian Lang                $this->_addCall('table_start', array($pos + 1), $pos);
5730cecf9d5Sandi                if ( trim($match) == '^' ) {
574433bef32Sandi                    $this->_addCall('tableheader', array(), $pos);
5750cecf9d5Sandi                } else {
576433bef32Sandi                    $this->_addCall('tablecell', array(), $pos);
5770cecf9d5Sandi                }
5780cecf9d5Sandi            break;
5790cecf9d5Sandi
5800cecf9d5Sandi            case DOKU_LEXER_EXIT:
58190df9a4dSAdrian Lang                $this->_addCall('table_end', array($pos), $pos);
5820cecf9d5Sandi                $this->CallWriter->process();
5830cecf9d5Sandi                $ReWriter = & $this->CallWriter;
5840cecf9d5Sandi                $this->CallWriter = & $ReWriter->CallWriter;
5850cecf9d5Sandi            break;
5860cecf9d5Sandi
5870cecf9d5Sandi            case DOKU_LEXER_UNMATCHED:
5880cecf9d5Sandi                if ( trim($match) != '' ) {
589433bef32Sandi                    $this->_addCall('cdata',array($match), $pos);
5900cecf9d5Sandi                }
5910cecf9d5Sandi            break;
5920cecf9d5Sandi
5930cecf9d5Sandi            case DOKU_LEXER_MATCHED:
5949ab75d9eSAndreas Gohr                if ( $match == ' ' ){
5959ab75d9eSAndreas Gohr                    $this->_addCall('cdata', array($match), $pos);
59625b97867Shakan.sandell                } else if ( preg_match('/:::/',$match) ) {
59725b97867Shakan.sandell                    $this->_addCall('rowspan', array($match), $pos);
598e205b721SAndreas Gohr                } else if ( preg_match('/\t+/',$match) ) {
5999ab75d9eSAndreas Gohr                    $this->_addCall('table_align', array($match), $pos);
600e205b721SAndreas Gohr                } else if ( preg_match('/ {2,}/',$match) ) {
601433bef32Sandi                    $this->_addCall('table_align', array($match), $pos);
6020cecf9d5Sandi                } else if ( $match == "\n|" ) {
603433bef32Sandi                    $this->_addCall('table_row', array(), $pos);
604433bef32Sandi                    $this->_addCall('tablecell', array(), $pos);
6050cecf9d5Sandi                } else if ( $match == "\n^" ) {
606433bef32Sandi                    $this->_addCall('table_row', array(), $pos);
607433bef32Sandi                    $this->_addCall('tableheader', array(), $pos);
6080cecf9d5Sandi                } else if ( $match == '|' ) {
609433bef32Sandi                    $this->_addCall('tablecell', array(), $pos);
6100cecf9d5Sandi                } else if ( $match == '^' ) {
611433bef32Sandi                    $this->_addCall('tableheader', array(), $pos);
6120cecf9d5Sandi                }
6130cecf9d5Sandi            break;
6140cecf9d5Sandi        }
61544881bd0Shenning.noren        return true;
6160cecf9d5Sandi    }
6170cecf9d5Sandi}
6180cecf9d5Sandi
6190cecf9d5Sandi//------------------------------------------------------------------------
6200cecf9d5Sandifunction Doku_Handler_Parse_Media($match) {
6210cecf9d5Sandi
6220cecf9d5Sandi    // Strip the opening and closing markup
6230cecf9d5Sandi    $link = preg_replace(array('/^\{\{/','/\}\}$/u'),'',$match);
6240cecf9d5Sandi
6250cecf9d5Sandi    // Split title from URL
6264b7f9e70STom N Harris    $link = explode('|',$link,2);
6270cecf9d5Sandi
6280cecf9d5Sandi    // Check alignment
6290cecf9d5Sandi    $ralign = (bool)preg_match('/^ /',$link[0]);
6300cecf9d5Sandi    $lalign = (bool)preg_match('/ $/',$link[0]);
6310cecf9d5Sandi
6320cecf9d5Sandi    // Logic = what's that ;)...
6330cecf9d5Sandi    if ( $lalign & $ralign ) {
6340cecf9d5Sandi        $align = 'center';
6350cecf9d5Sandi    } else if ( $ralign ) {
6360cecf9d5Sandi        $align = 'right';
6370cecf9d5Sandi    } else if ( $lalign ) {
6380cecf9d5Sandi        $align = 'left';
6390cecf9d5Sandi    } else {
6400ea51e63SMatt Perry        $align = null;
6410cecf9d5Sandi    }
6420cecf9d5Sandi
6430cecf9d5Sandi    // The title...
6440cecf9d5Sandi    if ( !isset($link[1]) ) {
6450ea51e63SMatt Perry        $link[1] = null;
6460cecf9d5Sandi    }
6470cecf9d5Sandi
6484826ab45Sandi    //remove aligning spaces
6494826ab45Sandi    $link[0] = trim($link[0]);
6500cecf9d5Sandi
6514826ab45Sandi    //split into src and parameters (using the very last questionmark)
6524826ab45Sandi    $pos = strrpos($link[0], '?');
6534826ab45Sandi    if($pos !== false){
6544826ab45Sandi        $src   = substr($link[0],0,$pos);
6554826ab45Sandi        $param = substr($link[0],$pos+1);
6560cecf9d5Sandi    }else{
6574826ab45Sandi        $src   = $link[0];
6584826ab45Sandi        $param = '';
6590cecf9d5Sandi    }
6600cecf9d5Sandi
6614826ab45Sandi    //parse width and height
6624826ab45Sandi    if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){
663443e135dSChristopher Smith        !empty($size[1]) ? $w = $size[1] : $w = null;
664443e135dSChristopher Smith        !empty($size[3]) ? $h = $size[3] : $h = null;
665fc1c55b1Shfuecks    } else {
6660ea51e63SMatt Perry        $w = null;
6670ea51e63SMatt Perry        $h = null;
6680cecf9d5Sandi    }
6690cecf9d5Sandi
670dc673a5bSjoe.lapp    //get linking command
671d35ab615Shenning.noren    if(preg_match('/nolink/i',$param)){
672dc673a5bSjoe.lapp        $linking = 'nolink';
673d35ab615Shenning.noren    }else if(preg_match('/direct/i',$param)){
674dc673a5bSjoe.lapp        $linking = 'direct';
6758acb3108SAndreas Gohr    }else if(preg_match('/linkonly/i',$param)){
6768acb3108SAndreas Gohr        $linking = 'linkonly';
677dc673a5bSjoe.lapp    }else{
678dc673a5bSjoe.lapp        $linking = 'details';
679dc673a5bSjoe.lapp    }
680dc673a5bSjoe.lapp
6814826ab45Sandi    //get caching command
6824826ab45Sandi    if (preg_match('/(nocache|recache)/i',$param,$cachemode)){
6834826ab45Sandi        $cache = $cachemode[1];
6840cecf9d5Sandi    }else{
6854826ab45Sandi        $cache = 'cache';
6860cecf9d5Sandi    }
6870cecf9d5Sandi
6880cecf9d5Sandi    // Check whether this is a local or remote image
6893e7e6067SKlap-in    if ( media_isexternal($src) ) {
6904826ab45Sandi        $call = 'externalmedia';
6910cecf9d5Sandi    } else {
6924826ab45Sandi        $call = 'internalmedia';
6930cecf9d5Sandi    }
6940cecf9d5Sandi
6950cecf9d5Sandi    $params = array(
6960cecf9d5Sandi        'type'=>$call,
6974826ab45Sandi        'src'=>$src,
6980cecf9d5Sandi        'title'=>$link[1],
6990cecf9d5Sandi        'align'=>$align,
7004826ab45Sandi        'width'=>$w,
7014826ab45Sandi        'height'=>$h,
7020cecf9d5Sandi        'cache'=>$cache,
703dc673a5bSjoe.lapp        'linking'=>$linking,
7040cecf9d5Sandi    );
7050cecf9d5Sandi
7060cecf9d5Sandi    return $params;
7070cecf9d5Sandi}
7080cecf9d5Sandi
7090cecf9d5Sandi//------------------------------------------------------------------------
7100cecf9d5Sandiclass Doku_Handler_CallWriter {
7110cecf9d5Sandi
7120cecf9d5Sandi    var $Handler;
7130cecf9d5Sandi
7140cecf9d5Sandi    function Doku_Handler_CallWriter(& $Handler) {
7150cecf9d5Sandi        $this->Handler = & $Handler;
7160cecf9d5Sandi    }
7170cecf9d5Sandi
7180cecf9d5Sandi    function writeCall($call) {
7190cecf9d5Sandi        $this->Handler->calls[] = $call;
7200cecf9d5Sandi    }
7210cecf9d5Sandi
7220cecf9d5Sandi    function writeCalls($calls) {
7230cecf9d5Sandi        $this->Handler->calls = array_merge($this->Handler->calls, $calls);
7240cecf9d5Sandi    }
725f4f02a0fSchris
726f4f02a0fSchris    // function is required, but since this call writer is first/highest in
727f4f02a0fSchris    // the chain it is not required to do anything
728f4f02a0fSchris    function finalise() {
7293893df8eSChristopher Smith        unset($this->Handler);
730f4f02a0fSchris    }
7310cecf9d5Sandi}
7320cecf9d5Sandi
7330cecf9d5Sandi//------------------------------------------------------------------------
7345587e44cSchris/**
7355587e44cSchris * Generic call writer class to handle nesting of rendering instructions
7365587e44cSchris * within a render instruction. Also see nest() method of renderer base class
7375587e44cSchris *
7385587e44cSchris * @author    Chris Smith <chris@jalakai.co.uk>
7395587e44cSchris */
7405587e44cSchrisclass Doku_Handler_Nest {
7415587e44cSchris
7425587e44cSchris    var $CallWriter;
7435587e44cSchris    var $calls = array();
7445587e44cSchris
7455587e44cSchris    var $closingInstruction;
7465587e44cSchris
7475587e44cSchris    /**
7485587e44cSchris     * constructor
7495587e44cSchris     *
7505587e44cSchris     * @param  object     $CallWriter     the renderers current call writer
7515587e44cSchris     * @param  string     $close          closing instruction name, this is required to properly terminate the
7525587e44cSchris     *                                    syntax mode if the document ends without a closing pattern
7535587e44cSchris     */
7545587e44cSchris    function Doku_Handler_Nest(& $CallWriter, $close="nest_close") {
7555587e44cSchris        $this->CallWriter = & $CallWriter;
7565587e44cSchris
7575587e44cSchris        $this->closingInstruction = $close;
7585587e44cSchris    }
7595587e44cSchris
7605587e44cSchris    function writeCall($call) {
7615587e44cSchris        $this->calls[] = $call;
7625587e44cSchris    }
7635587e44cSchris
7645587e44cSchris    function writeCalls($calls) {
7655587e44cSchris        $this->calls = array_merge($this->calls, $calls);
7665587e44cSchris    }
7675587e44cSchris
7685587e44cSchris    function finalise() {
7695587e44cSchris        $last_call = end($this->calls);
7705587e44cSchris        $this->writeCall(array($this->closingInstruction,array(), $last_call[2]));
7715587e44cSchris
7725587e44cSchris        $this->process();
7735587e44cSchris        $this->CallWriter->finalise();
7743893df8eSChristopher Smith        unset($this->CallWriter);
7755587e44cSchris    }
7765587e44cSchris
7775587e44cSchris    function process() {
77841624b31SChris Smith        // merge consecutive cdata
77941624b31SChris Smith        $unmerged_calls = $this->calls;
78041624b31SChris Smith        $this->calls = array();
78141624b31SChris Smith
78241624b31SChris Smith        foreach ($unmerged_calls as $call) $this->addCall($call);
78341624b31SChris Smith
7845587e44cSchris        $first_call = reset($this->calls);
7855587e44cSchris        $this->CallWriter->writeCall(array("nest", array($this->calls), $first_call[2]));
7865587e44cSchris    }
78741624b31SChris Smith
78841624b31SChris Smith    function addCall($call) {
78941624b31SChris Smith        $key = count($this->calls);
79041624b31SChris Smith        if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
79141624b31SChris Smith            $this->calls[$key-1][1][0] .= $call[1][0];
79273c47f3dSChris Smith        } else if ($call[0] == 'eol') {
79373c47f3dSChris Smith            // do nothing (eol shouldn't be allowed, to counter preformatted fix in #1652 & #1699)
79441624b31SChris Smith        } else {
79541624b31SChris Smith            $this->calls[] = $call;
79641624b31SChris Smith        }
79741624b31SChris Smith    }
7985587e44cSchris}
7995587e44cSchris
8000cecf9d5Sandiclass Doku_Handler_List {
8010cecf9d5Sandi
8020cecf9d5Sandi    var $CallWriter;
8030cecf9d5Sandi
8040cecf9d5Sandi    var $calls = array();
8050cecf9d5Sandi    var $listCalls = array();
8060cecf9d5Sandi    var $listStack = array();
8070cecf9d5Sandi
808*10bcc8aaSChristopher Smith    const NODE = 1;
809*10bcc8aaSChristopher Smith
8100cecf9d5Sandi    function Doku_Handler_List(& $CallWriter) {
8110cecf9d5Sandi        $this->CallWriter = & $CallWriter;
8120cecf9d5Sandi    }
8130cecf9d5Sandi
8140cecf9d5Sandi    function writeCall($call) {
8150cecf9d5Sandi        $this->calls[] = $call;
8160cecf9d5Sandi    }
8170cecf9d5Sandi
8180cecf9d5Sandi    // Probably not needed but just in case...
8190cecf9d5Sandi    function writeCalls($calls) {
8200cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
821f4f02a0fSchris#        $this->CallWriter->writeCalls($this->calls);
822f4f02a0fSchris    }
823f4f02a0fSchris
824f4f02a0fSchris    function finalise() {
825f4f02a0fSchris        $last_call = end($this->calls);
826f4f02a0fSchris        $this->writeCall(array('list_close',array(), $last_call[2]));
827f4f02a0fSchris
828f4f02a0fSchris        $this->process();
829f4f02a0fSchris        $this->CallWriter->finalise();
8303893df8eSChristopher Smith        unset($this->CallWriter);
8310cecf9d5Sandi    }
8320cecf9d5Sandi
8330cecf9d5Sandi    //------------------------------------------------------------------------
8340cecf9d5Sandi    function process() {
835f4f02a0fSchris
8360cecf9d5Sandi        foreach ( $this->calls as $call ) {
8370cecf9d5Sandi            switch ($call[0]) {
8380cecf9d5Sandi                case 'list_item':
8390cecf9d5Sandi                    $this->listOpen($call);
8400cecf9d5Sandi                break;
8410cecf9d5Sandi                case 'list_open':
8420cecf9d5Sandi                    $this->listStart($call);
8430cecf9d5Sandi                break;
8440cecf9d5Sandi                case 'list_close':
8450cecf9d5Sandi                    $this->listEnd($call);
8460cecf9d5Sandi                break;
8470cecf9d5Sandi                default:
8480cecf9d5Sandi                    $this->listContent($call);
8490cecf9d5Sandi                break;
8500cecf9d5Sandi            }
8510cecf9d5Sandi        }
8520cecf9d5Sandi
8530cecf9d5Sandi        $this->CallWriter->writeCalls($this->listCalls);
8540cecf9d5Sandi    }
8550cecf9d5Sandi
8560cecf9d5Sandi    //------------------------------------------------------------------------
8570cecf9d5Sandi    function listStart($call) {
8580cecf9d5Sandi        $depth = $this->interpretSyntax($call[1][0], $listType);
8590cecf9d5Sandi
8600cecf9d5Sandi        $this->initialDepth = $depth;
861*10bcc8aaSChristopher Smith        //                   array(list type, current depth, index of current listitem_open)
862*10bcc8aaSChristopher Smith        $this->listStack[] = array($listType, $depth, 1);
8630cecf9d5Sandi
8640cecf9d5Sandi        $this->listCalls[] = array('list'.$listType.'_open',array(),$call[2]);
8650cecf9d5Sandi        $this->listCalls[] = array('listitem_open',array(1),$call[2]);
8660cecf9d5Sandi        $this->listCalls[] = array('listcontent_open',array(),$call[2]);
8670cecf9d5Sandi    }
8680cecf9d5Sandi
8690cecf9d5Sandi    //------------------------------------------------------------------------
8700cecf9d5Sandi    function listEnd($call) {
87144881bd0Shenning.noren        $closeContent = true;
8720cecf9d5Sandi
8730cecf9d5Sandi        while ( $list = array_pop($this->listStack) ) {
8740cecf9d5Sandi            if ( $closeContent ) {
8750cecf9d5Sandi                $this->listCalls[] = array('listcontent_close',array(),$call[2]);
87644881bd0Shenning.noren                $closeContent = false;
8770cecf9d5Sandi            }
8780cecf9d5Sandi            $this->listCalls[] = array('listitem_close',array(),$call[2]);
8790cecf9d5Sandi            $this->listCalls[] = array('list'.$list[0].'_close', array(), $call[2]);
8800cecf9d5Sandi        }
8810cecf9d5Sandi    }
8820cecf9d5Sandi
8830cecf9d5Sandi    //------------------------------------------------------------------------
8840cecf9d5Sandi    function listOpen($call) {
8850cecf9d5Sandi        $depth = $this->interpretSyntax($call[1][0], $listType);
8860cecf9d5Sandi        $end = end($this->listStack);
887*10bcc8aaSChristopher Smith        $key = key($this->listStack);
8880cecf9d5Sandi
8890cecf9d5Sandi        // Not allowed to be shallower than initialDepth
8900cecf9d5Sandi        if ( $depth < $this->initialDepth ) {
8910cecf9d5Sandi            $depth = $this->initialDepth;
8920cecf9d5Sandi        }
8930cecf9d5Sandi
8940cecf9d5Sandi        //------------------------------------------------------------------------
8950cecf9d5Sandi        if ( $depth == $end[1] ) {
8960cecf9d5Sandi
8970cecf9d5Sandi            // Just another item in the list...
8980cecf9d5Sandi            if ( $listType == $end[0] ) {
8990cecf9d5Sandi                $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9000cecf9d5Sandi                $this->listCalls[] = array('listitem_close',array(),$call[2]);
9010cecf9d5Sandi                $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);
9020cecf9d5Sandi                $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9030cecf9d5Sandi
904*10bcc8aaSChristopher Smith                // new list item, update list stack's index into current listitem_open
905*10bcc8aaSChristopher Smith                $this->listStack[$key][2] = count($this->listCalls) - 2;
906*10bcc8aaSChristopher Smith
9070cecf9d5Sandi            // Switched list type...
9080cecf9d5Sandi            } else {
9090cecf9d5Sandi
9100cecf9d5Sandi                $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9110cecf9d5Sandi                $this->listCalls[] = array('listitem_close',array(),$call[2]);
9120cecf9d5Sandi                $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);
9130cecf9d5Sandi                $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
9140cecf9d5Sandi                $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
9150cecf9d5Sandi                $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9160cecf9d5Sandi
9170cecf9d5Sandi                array_pop($this->listStack);
918*10bcc8aaSChristopher Smith                $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
9190cecf9d5Sandi            }
9200cecf9d5Sandi
9210cecf9d5Sandi        //------------------------------------------------------------------------
9220cecf9d5Sandi        // Getting deeper...
9230cecf9d5Sandi        } else if ( $depth > $end[1] ) {
9240cecf9d5Sandi
9250cecf9d5Sandi            $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9260cecf9d5Sandi            $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
9270cecf9d5Sandi            $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
9280cecf9d5Sandi            $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9290cecf9d5Sandi
930*10bcc8aaSChristopher Smith            // set the node/leaf state of this item's parent listitem_open to NODE
931*10bcc8aaSChristopher Smith            $this->listCalls[$this->listStack[$key][2]][1][1] = self::NODE;
932*10bcc8aaSChristopher Smith
933*10bcc8aaSChristopher Smith            $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
9340cecf9d5Sandi
9350cecf9d5Sandi        //------------------------------------------------------------------------
9360cecf9d5Sandi        // Getting shallower ( $depth < $end[1] )
9370cecf9d5Sandi        } else {
9380cecf9d5Sandi            $this->listCalls[] = array('listcontent_close',array(),$call[2]);
9390cecf9d5Sandi            $this->listCalls[] = array('listitem_close',array(),$call[2]);
9400cecf9d5Sandi            $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);
9410cecf9d5Sandi
9420cecf9d5Sandi            // Throw away the end - done
9430cecf9d5Sandi            array_pop($this->listStack);
9440cecf9d5Sandi
9450cecf9d5Sandi            while (1) {
9460cecf9d5Sandi                $end = end($this->listStack);
947*10bcc8aaSChristopher Smith                $key = key($this->listStack);
9480cecf9d5Sandi
9490cecf9d5Sandi                if ( $end[1] <= $depth ) {
9500cecf9d5Sandi
9510cecf9d5Sandi                    // Normalize depths
9520cecf9d5Sandi                    $depth = $end[1];
9530cecf9d5Sandi
9540cecf9d5Sandi                    $this->listCalls[] = array('listitem_close',array(),$call[2]);
9550cecf9d5Sandi
9560cecf9d5Sandi                    if ( $end[0] == $listType ) {
9570cecf9d5Sandi                        $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);
9580cecf9d5Sandi                        $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9590cecf9d5Sandi
960*10bcc8aaSChristopher Smith                        // new list item, update list stack's index into current listitem_open
961*10bcc8aaSChristopher Smith                        $this->listStack[$key][2] = count($this->listCalls) - 2;
962*10bcc8aaSChristopher Smith
9630cecf9d5Sandi                    } else {
9640cecf9d5Sandi                        // Switching list type...
9650cecf9d5Sandi                        $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);
9660cecf9d5Sandi                        $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
9670cecf9d5Sandi                        $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
9680cecf9d5Sandi                        $this->listCalls[] = array('listcontent_open',array(),$call[2]);
9690cecf9d5Sandi
9700cecf9d5Sandi                        array_pop($this->listStack);
971*10bcc8aaSChristopher Smith                        $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
9720cecf9d5Sandi                    }
9730cecf9d5Sandi
9740cecf9d5Sandi                    break;
9750cecf9d5Sandi
9760cecf9d5Sandi                // Haven't dropped down far enough yet.... ( $end[1] > $depth )
9770cecf9d5Sandi                } else {
9780cecf9d5Sandi
9790cecf9d5Sandi                    $this->listCalls[] = array('listitem_close',array(),$call[2]);
9800cecf9d5Sandi                    $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);
9810cecf9d5Sandi
9820cecf9d5Sandi                    array_pop($this->listStack);
9830cecf9d5Sandi
9840cecf9d5Sandi                }
9850cecf9d5Sandi
9860cecf9d5Sandi            }
9870cecf9d5Sandi
9880cecf9d5Sandi        }
9890cecf9d5Sandi    }
9900cecf9d5Sandi
9910cecf9d5Sandi    //------------------------------------------------------------------------
9920cecf9d5Sandi    function listContent($call) {
9930cecf9d5Sandi        $this->listCalls[] = $call;
9940cecf9d5Sandi    }
9950cecf9d5Sandi
9960cecf9d5Sandi    //------------------------------------------------------------------------
9970cecf9d5Sandi    function interpretSyntax($match, & $type) {
9980cecf9d5Sandi        if ( substr($match,-1) == '*' ) {
9990cecf9d5Sandi            $type = 'u';
10000cecf9d5Sandi        } else {
10010cecf9d5Sandi            $type = 'o';
10020cecf9d5Sandi        }
10034b7f9e70STom N Harris        // Is the +1 needed? It used to be count(explode(...))
10044b7f9e70STom N Harris        // but I don't think the number is seen outside this handler
10054b7f9e70STom N Harris        return substr_count(str_replace("\t",'  ',$match), '  ') + 1;
10060cecf9d5Sandi    }
10070cecf9d5Sandi}
10080cecf9d5Sandi
10090cecf9d5Sandi//------------------------------------------------------------------------
10100cecf9d5Sandiclass Doku_Handler_Preformatted {
10110cecf9d5Sandi
10120cecf9d5Sandi    var $CallWriter;
10130cecf9d5Sandi
10140cecf9d5Sandi    var $calls = array();
10150cecf9d5Sandi    var $pos;
10160cecf9d5Sandi    var $text ='';
10170cecf9d5Sandi
10180cecf9d5Sandi
10190cecf9d5Sandi
10200cecf9d5Sandi    function Doku_Handler_Preformatted(& $CallWriter) {
10210cecf9d5Sandi        $this->CallWriter = & $CallWriter;
10220cecf9d5Sandi    }
10230cecf9d5Sandi
10240cecf9d5Sandi    function writeCall($call) {
10250cecf9d5Sandi        $this->calls[] = $call;
10260cecf9d5Sandi    }
10270cecf9d5Sandi
10280cecf9d5Sandi    // Probably not needed but just in case...
10290cecf9d5Sandi    function writeCalls($calls) {
10300cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
1031f4f02a0fSchris#        $this->CallWriter->writeCalls($this->calls);
1032f4f02a0fSchris    }
1033f4f02a0fSchris
1034f4f02a0fSchris    function finalise() {
1035f4f02a0fSchris        $last_call = end($this->calls);
1036f4f02a0fSchris        $this->writeCall(array('preformatted_end',array(), $last_call[2]));
1037f4f02a0fSchris
1038f4f02a0fSchris        $this->process();
1039f4f02a0fSchris        $this->CallWriter->finalise();
10403893df8eSChristopher Smith        unset($this->CallWriter);
10410cecf9d5Sandi    }
10420cecf9d5Sandi
10430cecf9d5Sandi    function process() {
10440cecf9d5Sandi        foreach ( $this->calls as $call ) {
10450cecf9d5Sandi            switch ($call[0]) {
10460cecf9d5Sandi                case 'preformatted_start':
10470cecf9d5Sandi                    $this->pos = $call[2];
10480cecf9d5Sandi                break;
10490cecf9d5Sandi                case 'preformatted_newline':
10500cecf9d5Sandi                    $this->text .= "\n";
10510cecf9d5Sandi                break;
10520cecf9d5Sandi                case 'preformatted_content':
10530cecf9d5Sandi                    $this->text .= $call[1][0];
10540cecf9d5Sandi                break;
10550cecf9d5Sandi                case 'preformatted_end':
105693a34bf3SChris Smith                    if (trim($this->text)) {
10570cecf9d5Sandi                        $this->CallWriter->writeCall(array('preformatted',array($this->text),$this->pos));
105893a34bf3SChris Smith                    }
105995c19ce7SChris Smith                    // see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open
106095c19ce7SChris Smith                    $this->CallWriter->writeCall(array('eol',array(),$this->pos));
106195c19ce7SChris Smith                    $this->CallWriter->writeCall(array('eol',array(),$this->pos));
10620cecf9d5Sandi                break;
10630cecf9d5Sandi            }
10640cecf9d5Sandi        }
10650cecf9d5Sandi    }
1066f4f02a0fSchris
10670cecf9d5Sandi}
10680cecf9d5Sandi
10690cecf9d5Sandi//------------------------------------------------------------------------
10700cecf9d5Sandiclass Doku_Handler_Quote {
10710cecf9d5Sandi
10720cecf9d5Sandi    var $CallWriter;
10730cecf9d5Sandi
10740cecf9d5Sandi    var $calls = array();
10750cecf9d5Sandi
10760cecf9d5Sandi    var $quoteCalls = array();
10770cecf9d5Sandi
10780cecf9d5Sandi    function Doku_Handler_Quote(& $CallWriter) {
10790cecf9d5Sandi        $this->CallWriter = & $CallWriter;
10800cecf9d5Sandi    }
10810cecf9d5Sandi
10820cecf9d5Sandi    function writeCall($call) {
10830cecf9d5Sandi        $this->calls[] = $call;
10840cecf9d5Sandi    }
10850cecf9d5Sandi
10860cecf9d5Sandi    // Probably not needed but just in case...
10870cecf9d5Sandi    function writeCalls($calls) {
10880cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
1089f4f02a0fSchris    }
1090f4f02a0fSchris
1091f4f02a0fSchris    function finalise() {
1092f4f02a0fSchris        $last_call = end($this->calls);
1093f4f02a0fSchris        $this->writeCall(array('quote_end',array(), $last_call[2]));
1094f4f02a0fSchris
1095f4f02a0fSchris        $this->process();
1096f4f02a0fSchris        $this->CallWriter->finalise();
10973893df8eSChristopher Smith        unset($this->CallWriter);
10980cecf9d5Sandi    }
10990cecf9d5Sandi
11000cecf9d5Sandi    function process() {
11010cecf9d5Sandi
11020cecf9d5Sandi        $quoteDepth = 1;
11030cecf9d5Sandi
11040cecf9d5Sandi        foreach ( $this->calls as $call ) {
11050cecf9d5Sandi            switch ($call[0]) {
11060cecf9d5Sandi
11070cecf9d5Sandi                case 'quote_start':
11080cecf9d5Sandi
11090cecf9d5Sandi                    $this->quoteCalls[] = array('quote_open',array(),$call[2]);
11100cecf9d5Sandi
11110cecf9d5Sandi                case 'quote_newline':
11120cecf9d5Sandi
11130cecf9d5Sandi                    $quoteLength = $this->getDepth($call[1][0]);
11140cecf9d5Sandi
11150cecf9d5Sandi                    if ( $quoteLength > $quoteDepth ) {
11160cecf9d5Sandi                        $quoteDiff = $quoteLength - $quoteDepth;
11170cecf9d5Sandi                        for ( $i = 1; $i <= $quoteDiff; $i++ ) {
11180cecf9d5Sandi                            $this->quoteCalls[] = array('quote_open',array(),$call[2]);
11190cecf9d5Sandi                        }
11200cecf9d5Sandi                    } else if ( $quoteLength < $quoteDepth ) {
11210cecf9d5Sandi                        $quoteDiff = $quoteDepth - $quoteLength;
11220cecf9d5Sandi                        for ( $i = 1; $i <= $quoteDiff; $i++ ) {
11230cecf9d5Sandi                            $this->quoteCalls[] = array('quote_close',array(),$call[2]);
11240cecf9d5Sandi                        }
112526426c64Schris                    } else {
112626426c64Schris                        if ($call[0] != 'quote_start') $this->quoteCalls[] = array('linebreak',array(),$call[2]);
11270cecf9d5Sandi                    }
11280cecf9d5Sandi
11290cecf9d5Sandi                    $quoteDepth = $quoteLength;
11300cecf9d5Sandi
11310cecf9d5Sandi                break;
11320cecf9d5Sandi
11330cecf9d5Sandi                case 'quote_end':
11340cecf9d5Sandi
11350cecf9d5Sandi                    if ( $quoteDepth > 1 ) {
11360cecf9d5Sandi                        $quoteDiff = $quoteDepth - 1;
11370cecf9d5Sandi                        for ( $i = 1; $i <= $quoteDiff; $i++ ) {
11380cecf9d5Sandi                            $this->quoteCalls[] = array('quote_close',array(),$call[2]);
11390cecf9d5Sandi                        }
11400cecf9d5Sandi                    }
11410cecf9d5Sandi
11420cecf9d5Sandi                    $this->quoteCalls[] = array('quote_close',array(),$call[2]);
11430cecf9d5Sandi
11440cecf9d5Sandi                    $this->CallWriter->writeCalls($this->quoteCalls);
11450cecf9d5Sandi                break;
11460cecf9d5Sandi
11470cecf9d5Sandi                default:
11480cecf9d5Sandi                    $this->quoteCalls[] = $call;
11490cecf9d5Sandi                break;
11500cecf9d5Sandi            }
11510cecf9d5Sandi        }
11520cecf9d5Sandi    }
11530cecf9d5Sandi
11540cecf9d5Sandi    function getDepth($marker) {
11550cecf9d5Sandi        preg_match('/>{1,}/', $marker, $matches);
11560cecf9d5Sandi        $quoteLength = strlen($matches[0]);
11570cecf9d5Sandi        return $quoteLength;
11580cecf9d5Sandi    }
11590cecf9d5Sandi}
11600cecf9d5Sandi
11610cecf9d5Sandi//------------------------------------------------------------------------
11620cecf9d5Sandiclass Doku_Handler_Table {
11630cecf9d5Sandi
11640cecf9d5Sandi    var $CallWriter;
11650cecf9d5Sandi
11660cecf9d5Sandi    var $calls = array();
11670cecf9d5Sandi    var $tableCalls = array();
11680cecf9d5Sandi    var $maxCols = 0;
11690cecf9d5Sandi    var $maxRows = 1;
11700cecf9d5Sandi    var $currentCols = 0;
117144881bd0Shenning.noren    var $firstCell = false;
11720cecf9d5Sandi    var $lastCellType = 'tablecell';
11739060b8b0SChristopher Smith    var $inTableHead = true;
1174cef031c1SChristopher Smith    var $currentRow = array('tableheader' => 0, 'tablecell' => 0);
11759060b8b0SChristopher Smith    var $countTableHeadRows = 0;
11760cecf9d5Sandi
11770cecf9d5Sandi    function Doku_Handler_Table(& $CallWriter) {
11780cecf9d5Sandi        $this->CallWriter = & $CallWriter;
11790cecf9d5Sandi    }
11800cecf9d5Sandi
11810cecf9d5Sandi    function writeCall($call) {
11820cecf9d5Sandi        $this->calls[] = $call;
11830cecf9d5Sandi    }
11840cecf9d5Sandi
11850cecf9d5Sandi    // Probably not needed but just in case...
11860cecf9d5Sandi    function writeCalls($calls) {
11870cecf9d5Sandi        $this->calls = array_merge($this->calls, $calls);
1188f4f02a0fSchris    }
1189f4f02a0fSchris
1190f4f02a0fSchris    function finalise() {
1191f4f02a0fSchris        $last_call = end($this->calls);
1192f4f02a0fSchris        $this->writeCall(array('table_end',array(), $last_call[2]));
1193f4f02a0fSchris
1194f4f02a0fSchris        $this->process();
1195f4f02a0fSchris        $this->CallWriter->finalise();
11963893df8eSChristopher Smith        unset($this->CallWriter);
11970cecf9d5Sandi    }
11980cecf9d5Sandi
11990cecf9d5Sandi    //------------------------------------------------------------------------
12000cecf9d5Sandi    function process() {
12010cecf9d5Sandi        foreach ( $this->calls as $call ) {
12020cecf9d5Sandi            switch ( $call[0] ) {
12030cecf9d5Sandi                case 'table_start':
12040cecf9d5Sandi                    $this->tableStart($call);
12050cecf9d5Sandi                break;
12060cecf9d5Sandi                case 'table_row':
1207aa92c4ccSAdrian Lang                    $this->tableRowClose($call);
12080cecf9d5Sandi                    $this->tableRowOpen(array('tablerow_open',$call[1],$call[2]));
12090cecf9d5Sandi                break;
12100cecf9d5Sandi                case 'tableheader':
12110cecf9d5Sandi                case 'tablecell':
12120cecf9d5Sandi                    $this->tableCell($call);
12130cecf9d5Sandi                break;
12140cecf9d5Sandi                case 'table_end':
1215aa92c4ccSAdrian Lang                    $this->tableRowClose($call);
12160cecf9d5Sandi                    $this->tableEnd($call);
12170cecf9d5Sandi                break;
12180cecf9d5Sandi                default:
12190cecf9d5Sandi                    $this->tableDefault($call);
12200cecf9d5Sandi                break;
12210cecf9d5Sandi            }
12220cecf9d5Sandi        }
12230cecf9d5Sandi        $this->CallWriter->writeCalls($this->tableCalls);
12240cecf9d5Sandi    }
12250cecf9d5Sandi
12260cecf9d5Sandi    function tableStart($call) {
122790df9a4dSAdrian Lang        $this->tableCalls[] = array('table_open',$call[1],$call[2]);
12280cecf9d5Sandi        $this->tableCalls[] = array('tablerow_open',array(),$call[2]);
122944881bd0Shenning.noren        $this->firstCell = true;
12300cecf9d5Sandi    }
12310cecf9d5Sandi
12320cecf9d5Sandi    function tableEnd($call) {
123307c2b1c7SAdrian Lang        $this->tableCalls[] = array('table_close',$call[1],$call[2]);
12340cecf9d5Sandi        $this->finalizeTable();
12350cecf9d5Sandi    }
12360cecf9d5Sandi
12370cecf9d5Sandi    function tableRowOpen($call) {
12380cecf9d5Sandi        $this->tableCalls[] = $call;
12390cecf9d5Sandi        $this->currentCols = 0;
124044881bd0Shenning.noren        $this->firstCell = true;
12410cecf9d5Sandi        $this->lastCellType = 'tablecell';
12420cecf9d5Sandi        $this->maxRows++;
1243cef031c1SChristopher Smith        if ($this->inTableHead) {
1244cef031c1SChristopher Smith            $this->currentRow = array('tablecell' => 0, 'tableheader' => 0);
1245cef031c1SChristopher Smith        }
12460cecf9d5Sandi    }
12470cecf9d5Sandi
12480cecf9d5Sandi    function tableRowClose($call) {
1249cef031c1SChristopher Smith        if ($this->inTableHead && ($this->inTableHead = $this->isTableHeadRow())) {
12509060b8b0SChristopher Smith            $this->countTableHeadRows++;
12519060b8b0SChristopher Smith        }
12520cecf9d5Sandi        // Strip off final cell opening and anything after it
12530cecf9d5Sandi        while ( $discard = array_pop($this->tableCalls ) ) {
12540cecf9d5Sandi
12550cecf9d5Sandi            if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') {
12560cecf9d5Sandi                break;
12570cecf9d5Sandi            }
1258cef031c1SChristopher Smith            if (!empty($this->currentRow[$discard[0]])) {
1259cef031c1SChristopher Smith                $this->currentRow[$discard[0]]--;
1260cef031c1SChristopher Smith            }
12610cecf9d5Sandi        }
1262aa92c4ccSAdrian Lang        $this->tableCalls[] = array('tablerow_close', array(), $call[2]);
12630cecf9d5Sandi
12640cecf9d5Sandi        if ( $this->currentCols > $this->maxCols ) {
12650cecf9d5Sandi            $this->maxCols = $this->currentCols;
12660cecf9d5Sandi        }
12670cecf9d5Sandi    }
12680cecf9d5Sandi
1269cef031c1SChristopher Smith    function isTableHeadRow() {
1270cef031c1SChristopher Smith        $td = $this->currentRow['tablecell'];
1271cef031c1SChristopher Smith        $th = $this->currentRow['tableheader'];
1272cef031c1SChristopher Smith
1273cef031c1SChristopher Smith        if (!$th || $td > 2) return false;
1274cef031c1SChristopher Smith        if (2*$td > $th) return false;
1275cef031c1SChristopher Smith
1276cef031c1SChristopher Smith        return true;
1277cef031c1SChristopher Smith    }
1278cef031c1SChristopher Smith
12790cecf9d5Sandi    function tableCell($call) {
1280cef031c1SChristopher Smith        if ($this->inTableHead) {
1281cef031c1SChristopher Smith            $this->currentRow[$call[0]]++;
12829060b8b0SChristopher Smith        }
12830cecf9d5Sandi        if ( !$this->firstCell ) {
12840cecf9d5Sandi
12850cecf9d5Sandi            // Increase the span
12860cecf9d5Sandi            $lastCall = end($this->tableCalls);
12870cecf9d5Sandi
12880cecf9d5Sandi            // A cell call which follows an open cell means an empty cell so span
12890cecf9d5Sandi            if ( $lastCall[0] == 'tablecell_open' || $lastCall[0] == 'tableheader_open' ) {
12900cecf9d5Sandi                 $this->tableCalls[] = array('colspan',array(),$call[2]);
12910cecf9d5Sandi
12920cecf9d5Sandi            }
12930cecf9d5Sandi
12940cecf9d5Sandi            $this->tableCalls[] = array($this->lastCellType.'_close',array(),$call[2]);
12950ea51e63SMatt Perry            $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
12960cecf9d5Sandi            $this->lastCellType = $call[0];
12970cecf9d5Sandi
12980cecf9d5Sandi        } else {
12990cecf9d5Sandi
13000ea51e63SMatt Perry            $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
13010cecf9d5Sandi            $this->lastCellType = $call[0];
130244881bd0Shenning.noren            $this->firstCell = false;
13030cecf9d5Sandi
13040cecf9d5Sandi        }
13050cecf9d5Sandi
13060cecf9d5Sandi        $this->currentCols++;
13070cecf9d5Sandi    }
13080cecf9d5Sandi
13090cecf9d5Sandi    function tableDefault($call) {
13100cecf9d5Sandi        $this->tableCalls[] = $call;
13110cecf9d5Sandi    }
13120cecf9d5Sandi
13130cecf9d5Sandi    function finalizeTable() {
13140cecf9d5Sandi
13150cecf9d5Sandi        // Add the max cols and rows to the table opening
13160cecf9d5Sandi        if ( $this->tableCalls[0][0] == 'table_open' ) {
13170cecf9d5Sandi            // Adjust to num cols not num col delimeters
13180cecf9d5Sandi            $this->tableCalls[0][1][] = $this->maxCols - 1;
13190cecf9d5Sandi            $this->tableCalls[0][1][] = $this->maxRows;
132090df9a4dSAdrian Lang            $this->tableCalls[0][1][] = array_shift($this->tableCalls[0][1]);
13210cecf9d5Sandi        } else {
13220cecf9d5Sandi            trigger_error('First element in table call list is not table_open');
13230cecf9d5Sandi        }
13240cecf9d5Sandi
13250cecf9d5Sandi        $lastRow = 0;
13260cecf9d5Sandi        $lastCell = 0;
132725b97867Shakan.sandell        $cellKey = array();
13280cecf9d5Sandi        $toDelete = array();
13290cecf9d5Sandi
1330cef031c1SChristopher Smith        // if still in tableheader, then there can be no table header
1331cef031c1SChristopher Smith        // as all rows can't be within <THEAD>
1332cef031c1SChristopher Smith        if ($this->inTableHead) {
1333cef031c1SChristopher Smith            $this->inTableHead = false;
1334cef031c1SChristopher Smith            $this->countTableHeadRows = 0;
1335cef031c1SChristopher Smith        }
1336cef031c1SChristopher Smith
13370cecf9d5Sandi        // Look for the colspan elements and increment the colspan on the
13380cecf9d5Sandi        // previous non-empty opening cell. Once done, delete all the cells
13390cecf9d5Sandi        // that contain colspans
13406606d6fcSAdrian Lang        for ($key = 0 ; $key < count($this->tableCalls) ; ++$key) {
13416606d6fcSAdrian Lang            $call = $this->tableCalls[$key];
13420cecf9d5Sandi
1343aa92c4ccSAdrian Lang            switch ($call[0]) {
13449060b8b0SChristopher Smith                case 'table_open' :
13459060b8b0SChristopher Smith                    if($this->countTableHeadRows) {
13469060b8b0SChristopher Smith                        array_splice($this->tableCalls, $key+1, 0, array(
13479060b8b0SChristopher Smith                              array('tablethead_open', array(), $call[2]))
13489060b8b0SChristopher Smith                        );
13499060b8b0SChristopher Smith                    }
13509060b8b0SChristopher Smith                    break;
13519060b8b0SChristopher Smith
1352aa92c4ccSAdrian Lang                case 'tablerow_open':
13530cecf9d5Sandi
135425b97867Shakan.sandell                    $lastRow++;
135525b97867Shakan.sandell                    $lastCell = 0;
1356aa92c4ccSAdrian Lang                    break;
13570cecf9d5Sandi
1358aa92c4ccSAdrian Lang                case 'tablecell_open':
1359aa92c4ccSAdrian Lang                case 'tableheader_open':
13600cecf9d5Sandi
136125b97867Shakan.sandell                    $lastCell++;
136225b97867Shakan.sandell                    $cellKey[$lastRow][$lastCell] = $key;
1363aa92c4ccSAdrian Lang                    break;
13640cecf9d5Sandi
1365aa92c4ccSAdrian Lang                case 'table_align':
13660cecf9d5Sandi
1367e03b8b2eSAdrian Lang                    $prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));
1368e03b8b2eSAdrian Lang                    $next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));
1369e03b8b2eSAdrian Lang                    // If the cell is empty, align left
1370e03b8b2eSAdrian Lang                    if ($prev && $next) {
1371e03b8b2eSAdrian Lang                        $this->tableCalls[$key-1][1][1] = 'left';
1372e03b8b2eSAdrian Lang
13730cecf9d5Sandi                    // If the previous element was a cell open, align right
1374e03b8b2eSAdrian Lang                    } elseif ($prev) {
13750cecf9d5Sandi                        $this->tableCalls[$key-1][1][1] = 'right';
13760cecf9d5Sandi
1377e03b8b2eSAdrian Lang                    // If the next element is the close of an element, align either center or left
1378e03b8b2eSAdrian Lang                    } elseif ( $next) {
137925b97867Shakan.sandell                        if ( $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] == 'right' ) {
138025b97867Shakan.sandell                            $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'center';
13810cecf9d5Sandi                        } else {
138225b97867Shakan.sandell                            $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'left';
13830cecf9d5Sandi                        }
13840cecf9d5Sandi
13850cecf9d5Sandi                    }
13860cecf9d5Sandi
13870cecf9d5Sandi                    // Now convert the whitespace back to cdata
13880cecf9d5Sandi                    $this->tableCalls[$key][0] = 'cdata';
1389aa92c4ccSAdrian Lang                    break;
13900cecf9d5Sandi
1391aa92c4ccSAdrian Lang                case 'colspan':
13920cecf9d5Sandi
139344881bd0Shenning.noren                    $this->tableCalls[$key-1][1][0] = false;
13940cecf9d5Sandi
139525b97867Shakan.sandell                    for($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) {
13960cecf9d5Sandi
13970cecf9d5Sandi                        if ( $this->tableCalls[$i][0] == 'tablecell_open' || $this->tableCalls[$i][0] == 'tableheader_open' ) {
13980cecf9d5Sandi
139944881bd0Shenning.noren                            if ( false !== $this->tableCalls[$i][1][0] ) {
14000cecf9d5Sandi                                $this->tableCalls[$i][1][0]++;
14010cecf9d5Sandi                                break;
14020cecf9d5Sandi                            }
14030cecf9d5Sandi
14040cecf9d5Sandi                        }
14050cecf9d5Sandi                    }
14060cecf9d5Sandi
14070cecf9d5Sandi                    $toDelete[] = $key-1;
14080cecf9d5Sandi                    $toDelete[] = $key;
14090cecf9d5Sandi                    $toDelete[] = $key+1;
1410aa92c4ccSAdrian Lang                    break;
141125b97867Shakan.sandell
1412aa92c4ccSAdrian Lang                case 'rowspan':
141325b97867Shakan.sandell
141425b97867Shakan.sandell                    if ( $this->tableCalls[$key-1][0] == 'cdata' ) {
141525b97867Shakan.sandell                        // ignore rowspan if previous call was cdata (text mixed with :::) we don't have to check next call as that wont match regex
141625b97867Shakan.sandell                        $this->tableCalls[$key][0] = 'cdata';
141725b97867Shakan.sandell
141825b97867Shakan.sandell                    } else {
141925b97867Shakan.sandell
14206606d6fcSAdrian Lang                        $spanning_cell = null;
14219060b8b0SChristopher Smith
14229060b8b0SChristopher Smith                        // can't cross thead/tbody boundary
14239060b8b0SChristopher Smith                        if (!$this->countTableHeadRows || ($lastRow-1 != $this->countTableHeadRows)) {
142425b97867Shakan.sandell                            for($i = $lastRow-1; $i > 0; $i--) {
142525b97867Shakan.sandell
142625b97867Shakan.sandell                                if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) {
142725b97867Shakan.sandell
14286606d6fcSAdrian Lang                                    if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) {
14296606d6fcSAdrian Lang                                        $spanning_cell = $i;
143025b97867Shakan.sandell                                        break;
143125b97867Shakan.sandell                                    }
143225b97867Shakan.sandell
143325b97867Shakan.sandell                                }
143425b97867Shakan.sandell                            }
14359060b8b0SChristopher Smith                        }
14366606d6fcSAdrian Lang                        if (is_null($spanning_cell)) {
14376606d6fcSAdrian Lang                            // No spanning cell found, so convert this cell to
14386606d6fcSAdrian Lang                            // an empty one to avoid broken tables
14396a7e97d5SGerrit Uitslag                            $this->tableCalls[$key][0] = 'cdata';
14406a7e97d5SGerrit Uitslag                            $this->tableCalls[$key][1][0] = '';
14416606d6fcSAdrian Lang                            continue;
14426606d6fcSAdrian Lang                        }
14436606d6fcSAdrian Lang                        $this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++;
14446606d6fcSAdrian Lang
14456606d6fcSAdrian Lang                        $this->tableCalls[$key-1][1][2] = false;
144625b97867Shakan.sandell
144725b97867Shakan.sandell                        $toDelete[] = $key-1;
144825b97867Shakan.sandell                        $toDelete[] = $key;
144925b97867Shakan.sandell                        $toDelete[] = $key+1;
145025b97867Shakan.sandell                    }
1451aa92c4ccSAdrian Lang                    break;
1452aa92c4ccSAdrian Lang
14536606d6fcSAdrian Lang                case 'tablerow_close':
14546606d6fcSAdrian Lang
14556606d6fcSAdrian Lang                    // Fix broken tables by adding missing cells
14566606d6fcSAdrian Lang                    while (++$lastCell < $this->maxCols) {
14576606d6fcSAdrian Lang                        array_splice($this->tableCalls, $key, 0, array(
14586606d6fcSAdrian Lang                               array('tablecell_open', array(1, null, 1), $call[2]),
14596606d6fcSAdrian Lang                               array('cdata', array(''), $call[2]),
14606606d6fcSAdrian Lang                               array('tablecell_close', array(), $call[2])));
14616606d6fcSAdrian Lang                        $key += 3;
14626606d6fcSAdrian Lang                    }
14636606d6fcSAdrian Lang
14649060b8b0SChristopher Smith                    if($this->countTableHeadRows == $lastRow) {
1465f05a1cc5SGerrit Uitslag                        array_splice($this->tableCalls, $key+1, 0, array(
1466f05a1cc5SGerrit Uitslag                              array('tablethead_close', array(), $call[2])));
1467f05a1cc5SGerrit Uitslag                    }
14686606d6fcSAdrian Lang                    break;
14696606d6fcSAdrian Lang
14700cecf9d5Sandi            }
14710cecf9d5Sandi        }
14720cecf9d5Sandi
14739ab75d9eSAndreas Gohr        // condense cdata
14749ab75d9eSAndreas Gohr        $cnt = count($this->tableCalls);
14759ab75d9eSAndreas Gohr        for( $key = 0; $key < $cnt; $key++){
14769ab75d9eSAndreas Gohr            if($this->tableCalls[$key][0] == 'cdata'){
14779ab75d9eSAndreas Gohr                $ckey = $key;
14789ab75d9eSAndreas Gohr                $key++;
14799ab75d9eSAndreas Gohr                while($this->tableCalls[$key][0] == 'cdata'){
14809ab75d9eSAndreas Gohr                    $this->tableCalls[$ckey][1][0] .= $this->tableCalls[$key][1][0];
14819ab75d9eSAndreas Gohr                    $toDelete[] = $key;
14829ab75d9eSAndreas Gohr                    $key++;
14839ab75d9eSAndreas Gohr                }
14849ab75d9eSAndreas Gohr                continue;
14859ab75d9eSAndreas Gohr            }
14869ab75d9eSAndreas Gohr        }
14879ab75d9eSAndreas Gohr
14880cecf9d5Sandi        foreach ( $toDelete as $delete ) {
14890cecf9d5Sandi            unset($this->tableCalls[$delete]);
14900cecf9d5Sandi        }
14910cecf9d5Sandi        $this->tableCalls = array_values($this->tableCalls);
14920cecf9d5Sandi    }
14930cecf9d5Sandi}
14940cecf9d5Sandi
14950cecf9d5Sandi
14962a27e99aSandi/**
14972a27e99aSandi * Handler for paragraphs
14982a27e99aSandi *
14990b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com>
15002a27e99aSandi */
15010cecf9d5Sandiclass Doku_Handler_Block {
15020cecf9d5Sandi    var $calls = array();
15039569a107SDanny Lin    var $skipEol = false;
150453bfcb59SChristopher Smith    var $inParagraph = false;
15050cecf9d5Sandi
1506af146da0Sandi    // Blocks these should not be inside paragraphs
15070cecf9d5Sandi    var $blockOpen = array(
15080cecf9d5Sandi            'header',
1509df9add72Schris            'listu_open','listo_open','listitem_open','listcontent_open',
1510f05a1cc5SGerrit Uitslag            'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open',
15110cecf9d5Sandi            'quote_open',
151276aa94b7Schris            'code','file','hr','preformatted','rss',
151307f89c3cSAnika Henke            'htmlblock','phpblock',
15149569a107SDanny Lin            'footnote_open',
15150cecf9d5Sandi        );
15160cecf9d5Sandi
15170cecf9d5Sandi    var $blockClose = array(
15180cecf9d5Sandi            'header',
1519df9add72Schris            'listu_close','listo_close','listitem_close','listcontent_close',
1520f05a1cc5SGerrit Uitslag            'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close',
15210cecf9d5Sandi            'quote_close',
152276aa94b7Schris            'code','file','hr','preformatted','rss',
152307f89c3cSAnika Henke            'htmlblock','phpblock',
15249569a107SDanny Lin            'footnote_close',
15250cecf9d5Sandi        );
15260cecf9d5Sandi
1527af146da0Sandi    // Stacks can contain paragraphs
15280cecf9d5Sandi    var $stackOpen = array(
15299569a107SDanny Lin        'section_open',
15300cecf9d5Sandi        );
15310cecf9d5Sandi
15320cecf9d5Sandi    var $stackClose = array(
15339569a107SDanny Lin        'section_close',
15340cecf9d5Sandi        );
15350cecf9d5Sandi
1536af146da0Sandi
1537af146da0Sandi    /**
1538af146da0Sandi     * Constructor. Adds loaded syntax plugins to the block and stack
1539af146da0Sandi     * arrays
1540af146da0Sandi     *
1541af146da0Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1542af146da0Sandi     */
1543af146da0Sandi    function Doku_Handler_Block(){
1544af146da0Sandi        global $DOKU_PLUGINS;
1545af146da0Sandi        //check if syntax plugins were loaded
154603c4aec3Schris        if(empty($DOKU_PLUGINS['syntax'])) return;
1547af146da0Sandi        foreach($DOKU_PLUGINS['syntax'] as $n => $p){
1548af146da0Sandi            $ptype = $p->getPType();
1549af146da0Sandi            if($ptype == 'block'){
1550af146da0Sandi                $this->blockOpen[]  = 'plugin_'.$n;
1551af146da0Sandi                $this->blockClose[] = 'plugin_'.$n;
1552af146da0Sandi            }elseif($ptype == 'stack'){
1553af146da0Sandi                $this->stackOpen[]  = 'plugin_'.$n;
1554af146da0Sandi                $this->stackClose[] = 'plugin_'.$n;
1555af146da0Sandi            }
1556af146da0Sandi        }
1557af146da0Sandi    }
1558af146da0Sandi
1559b5a0b131SDanny Lin    function openParagraph($pos){
15609569a107SDanny Lin        if ($this->inParagraph) return;
1561b5a0b131SDanny Lin        $this->calls[] = array('p_open',array(), $pos);
1562b5a0b131SDanny Lin        $this->inParagraph = true;
15639569a107SDanny Lin        $this->skipEol = true;
1564b5a0b131SDanny Lin    }
1565b5a0b131SDanny Lin
15662a27e99aSandi    /**
15672a27e99aSandi     * Close a paragraph if needed
15682a27e99aSandi     *
15692a27e99aSandi     * This function makes sure there are no empty paragraphs on the stack
15702a27e99aSandi     *
15712a27e99aSandi     * @author Andreas Gohr <andi@splitbrain.org>
15722a27e99aSandi     */
1573506ae684Sandi    function closeParagraph($pos){
15749569a107SDanny Lin        if (!$this->inParagraph) return;
1575506ae684Sandi        // look back if there was any content - we don't want empty paragraphs
1576506ae684Sandi        $content = '';
1577faba9a35SAndreas Gohr        $ccount = count($this->calls);
1578faba9a35SAndreas Gohr        for($i=$ccount-1; $i>=0; $i--){
1579506ae684Sandi            if($this->calls[$i][0] == 'p_open'){
1580506ae684Sandi                break;
1581506ae684Sandi            }elseif($this->calls[$i][0] == 'cdata'){
1582506ae684Sandi                $content .= $this->calls[$i][1][0];
1583506ae684Sandi            }else{
1584506ae684Sandi                $content = 'found markup';
1585506ae684Sandi                break;
1586506ae684Sandi            }
1587506ae684Sandi        }
1588506ae684Sandi
1589506ae684Sandi        if(trim($content)==''){
1590506ae684Sandi            //remove the whole paragraph
1591a86cc527SAndreas Gohr            //array_splice($this->calls,$i); // <- this is much slower than the loop below
1592d8f7a7f3SAndreas Gohr            for($x=$ccount; $x>$i; $x--) array_pop($this->calls);
1593506ae684Sandi        }else{
15949569a107SDanny Lin            // remove ending linebreaks in the paragraph
15959569a107SDanny Lin            $i=count($this->calls)-1;
15969569a107SDanny Lin            if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL);
1597506ae684Sandi            $this->calls[] = array('p_close',array(), $pos);
1598506ae684Sandi        }
1599e1c10e4dSchris
160044881bd0Shenning.noren        $this->inParagraph = false;
16019569a107SDanny Lin        $this->skipEol = true;
16020cecf9d5Sandi    }
160341624b31SChris Smith
160441624b31SChris Smith    function addCall($call) {
160541624b31SChris Smith        $key = count($this->calls);
160641624b31SChris Smith        if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
160741624b31SChris Smith            $this->calls[$key-1][1][0] .= $call[1][0];
160841624b31SChris Smith        } else {
160941624b31SChris Smith            $this->calls[] = $call;
161041624b31SChris Smith        }
161141624b31SChris Smith    }
16129569a107SDanny Lin
16139569a107SDanny Lin    // simple version of addCall, without checking cdata
16149569a107SDanny Lin    function storeCall($call) {
16159569a107SDanny Lin        $this->calls[] = $call;
16169569a107SDanny Lin    }
16179569a107SDanny Lin
16189569a107SDanny Lin    /**
16199569a107SDanny Lin     * Processes the whole instruction stack to open and close paragraphs
16209569a107SDanny Lin     *
16219569a107SDanny Lin     * @author Harry Fuecks <hfuecks@gmail.com>
16229569a107SDanny Lin     * @author Andreas Gohr <andi@splitbrain.org>
16239569a107SDanny Lin     */
16249569a107SDanny Lin    function process($calls) {
16259569a107SDanny Lin        // open first paragraph
16269569a107SDanny Lin        $this->openParagraph(0);
16279569a107SDanny Lin        foreach ( $calls as $key => $call ) {
16289569a107SDanny Lin            $cname = $call[0];
16299569a107SDanny Lin            if ($cname == 'plugin') {
16309569a107SDanny Lin                $cname='plugin_'.$call[1][0];
16319569a107SDanny Lin                $plugin = true;
16329569a107SDanny Lin                $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));
16339569a107SDanny Lin                $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));
16349569a107SDanny Lin            } else {
16359569a107SDanny Lin                $plugin = false;
16369569a107SDanny Lin            }
16379569a107SDanny Lin            /* stack */
16389569a107SDanny Lin            if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) {
16399569a107SDanny Lin                $this->closeParagraph($call[2]);
16409569a107SDanny Lin                $this->storeCall($call);
16419569a107SDanny Lin                $this->openParagraph($call[2]);
16429569a107SDanny Lin                continue;
16439569a107SDanny Lin            }
16449569a107SDanny Lin            if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) {
16459569a107SDanny Lin                $this->closeParagraph($call[2]);
16469569a107SDanny Lin                $this->storeCall($call);
16479569a107SDanny Lin                $this->openParagraph($call[2]);
16489569a107SDanny Lin                continue;
16499569a107SDanny Lin            }
16509569a107SDanny Lin            /* block */
16519569a107SDanny Lin            // If it's a substition it opens and closes at the same call.
16529569a107SDanny Lin            // To make sure next paragraph is correctly started, let close go first.
16539569a107SDanny Lin            if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
16549569a107SDanny Lin                $this->closeParagraph($call[2]);
16559569a107SDanny Lin                $this->storeCall($call);
16569569a107SDanny Lin                $this->openParagraph($call[2]);
16579569a107SDanny Lin                continue;
16589569a107SDanny Lin            }
16599569a107SDanny Lin            if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) {
16609569a107SDanny Lin                $this->closeParagraph($call[2]);
16619569a107SDanny Lin                $this->storeCall($call);
16629569a107SDanny Lin                continue;
16639569a107SDanny Lin            }
16649569a107SDanny Lin            /* eol */
16659569a107SDanny Lin            if ( $cname == 'eol' ) {
16669569a107SDanny Lin                // Check this isn't an eol instruction to skip...
16679569a107SDanny Lin                if ( !$this->skipEol ) {
16689569a107SDanny Lin                    // Next is EOL => double eol => mark as paragraph
16699569a107SDanny Lin                    if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
16709569a107SDanny Lin                        $this->closeParagraph($call[2]);
16719569a107SDanny Lin                        $this->openParagraph($call[2]);
16729569a107SDanny Lin                    } else {
16739569a107SDanny Lin                        //if this is just a single eol make a space from it
16749569a107SDanny Lin                        $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
16759569a107SDanny Lin                    }
16769569a107SDanny Lin                }
16779569a107SDanny Lin                continue;
16789569a107SDanny Lin            }
16799569a107SDanny Lin            /* normal */
16809569a107SDanny Lin            $this->addCall($call);
16819569a107SDanny Lin            $this->skipEol = false;
16829569a107SDanny Lin        }
16839569a107SDanny Lin        // close last paragraph
16849569a107SDanny Lin        $call = end($this->calls);
16859569a107SDanny Lin        $this->closeParagraph($call[2]);
16869569a107SDanny Lin        return $this->calls;
16879569a107SDanny Lin    }
16880cecf9d5Sandi}
16892a27e99aSandi
1690e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1691