1<?php
2
3/**
4 * Created by IntelliJ IDEA.
5 * User: michael
6 * Date: 7/7/17
7 * Time: 1:49 PM
8 */
9
10namespace dokuwiki\plugin\prosemirror\parser;
11
12class RootNode extends Node
13{
14    /** @var Node[] */
15    protected $subnodes = [];
16
17    protected $attr = [];
18
19    public function __construct($data, Node $ignored = null)
20    {
21        $this->attr = $data['attrs'] ?? null;
22        foreach ($data['content'] as $node) {
23            $this->subnodes[] = self::getSubNode($node, $this);
24        }
25    }
26
27    public function toSyntax()
28    {
29        $doc = '';
30        foreach ($this->subnodes as $subnode) {
31            $doc .= $subnode->toSyntax();
32            $doc = rtrim($doc);
33            $doc .= "\n\n";
34        }
35        $doc .= $this->getMacroSyntax();
36        return $doc;
37    }
38
39    /**
40     * Get the syntax for each active macro
41     *
42     * This produces the syntax representation for the and NOCACHE NOTOC macros
43     *
44     * @return string empty string or a string with a line for each active macro
45     */
46    protected function getMacroSyntax()
47    {
48        $syntax = '';
49        if (!empty($this->attr['nocache'])) {
50            $syntax .= "~~NOCACHE~~\n";
51        }
52        if (!empty($this->attr['notoc'])) {
53            $syntax .= "~~NOTOC~~\n";
54        }
55        return $syntax;
56    }
57}
58