File: Preformatted.php

package info (click to toggle)
dokuwiki 2025-05-14.b%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 24,928 kB
  • sloc: php: 99,723; javascript: 3,741; sh: 599; makefile: 70; xml: 34
file content (48 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace dokuwiki\Parsing\Handler;

class Preformatted extends AbstractRewriter
{
    protected $pos;
    protected $text = '';

    /** @inheritdoc */
    public function finalise()
    {
        $last_call = end($this->calls);
        $this->writeCall(['preformatted_end', [], $last_call[2]]);

        $this->process();
        $this->callWriter->finalise();
        unset($this->callWriter);
    }

    /** @inheritdoc */
    public function process()
    {
        foreach ($this->calls as $call) {
            switch ($call[0]) {
                case 'preformatted_start':
                    $this->pos = $call[2];
                    break;
                case 'preformatted_newline':
                    $this->text .= "\n";
                    break;
                case 'preformatted_content':
                    $this->text .= $call[1][0];
                    break;
                case 'preformatted_end':
                    if (trim($this->text)) {
                        $this->callWriter->writeCall(['preformatted', [$this->text], $this->pos]);
                    }
                    // see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open
                    $this->callWriter->writeCall(['eol', [], $this->pos]);
                    $this->callWriter->writeCall(['eol', [], $this->pos]);
                    break;
            }
        }

        return $this->callWriter;
    }
}