1<?php 2 3namespace dokuwiki\plugin\diagrams\parser; 4 5use dokuwiki\plugin\prosemirror\parser\Node; 6 7/** 8 * Represents an embedded diagram 9 * 10 * Note: for mediafile diagrams the image node is reused 11 */ 12class DiagramsNode extends Node 13{ 14 /** 15 * @var Node 16 */ 17 protected $parent; 18 19 /** 20 * @var mixed 21 */ 22 protected $data; 23 24 /** @inheritdoc */ 25 public function __construct($data, Node $parent) 26 { 27 $this->parent = &$parent; 28 $this->data = $data; 29 } 30 31 /** @inheritdoc */ 32 public function toSyntax() 33 { 34 $openingTag = '<diagram'; 35 if (!empty($this->data['attrs']['align'])) { 36 $openingTag .= ' ' . $this->data['attrs']['align']; 37 } 38 if (!empty($this->data['attrs']['width']) && !empty($this->data['attrs']['height'])) { 39 $openingTag .= ' ' . $this->data['attrs']['width'] . 'x' . $this->data['attrs']['height']; 40 } 41 if (!empty($this->data['attrs']['title'])) { 42 $openingTag .= ' |' . $this->data['attrs']['title']; 43 } 44 $openingTag .= '>'; 45 46 $svg = $this->data['attrs']['url']; 47 if (substr($svg, 0, 26) !== 'data:image/svg+xml;base64,') { 48 throw new \Exception('bad data uri "' . substr($svg, 0, 26) . '"'); 49 } 50 $svg = base64_decode(substr($svg, 26)); 51 return $openingTag . $svg . "</diagram>"; 52 } 53} 54