xref: /plugin/diagrams/parser/DiagramsNode.php (revision 929bdadda0ca0ed07b6e51692be77e937095527f)
1<?php
2
3namespace dokuwiki\plugin\diagrams\parser;
4
5use dokuwiki\plugin\prosemirror\parser\Node;
6
7class DiagramsNode extends Node
8{
9    /**
10     * @var Node
11     */
12    protected $parent;
13
14    /**
15     * @var mixed
16     */
17    protected $data;
18
19    public function __construct($data, Node $parent)
20    {
21        $this->parent = &$parent;
22        $this->data = $data;
23    }
24
25
26    public function toSyntax()
27    {
28        $openingTag = '<diagram';
29        if (!empty($this->data['attrs']['align'])) {
30            $openingTag .= ' ' . $this->data['attrs']['align'];
31        }
32        $openingTag .= '>';
33
34        $svg = $this->data['attrs']['url'];
35        if (substr($svg, 0, 26) !== 'data:image/svg+xml;base64,') {
36            throw new \Exception('bad data uri "'.substr($svg, 0, 26).'"');
37        }
38        $svg = base64_decode(substr($svg, 26));
39        return $openingTag . $svg . "</diagram>";
40    }
41
42
43}
44