1<?php
2
3namespace dokuwiki\plugin\wordimport\docx;
4
5/**
6 * A code block
7 *
8 * Word doesn't have a specific code block element. We treat monospace paragraphs as code blocks
9 *
10 * This is basically a paragraph without any formatting and with real line breaks
11 */
12class CodeBlock extends AbstractParagraph
13{
14    /** @var string The raw text of the code block */
15    protected $text = '';
16
17    /** @inheritdoc */
18    public function parse()
19    {
20        $runs = $this->p->xpath('w:r');
21        foreach ($runs as $run) {
22            $tr = new TextRun($this->docx, $run, "\n"); // use real line breaks
23            $this->text .= $tr->__toString();
24        }
25    }
26
27    /** @inheritdoc */
28    public function __toString(): string
29    {
30        return '<code>' . "\n" . $this->text . "\n" . '</code>';
31    }
32}
33