HeadingNode::toSyntax()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
/**
4
 * Created by IntelliJ IDEA.
5
 * User: michael
6
 * Date: 7/7/17
7
 * Time: 4:49 PM
8
 */
9
10
namespace dokuwiki\plugin\prosemirror\parser;
11
12
class HeadingNode extends Node
13
{
14
    protected $parent;
15
    protected $level;
16
    protected $text;
17
18
    public function __construct($data, Node $parent)
19
    {
20
        if (trim($data['content'][0]['text']) === '') {
21
            return;
22
        }
23
24
        $this->parent = &$parent;
25
        $this->level = $data['attrs']['level'];
26
        $this->text = $data['content'][0]['text'];
27
    }
28
29
    public function toSyntax()
30
    {
31
        $wrapper = [
32
            1 => '======',
33
            2 => '=====',
34
            3 => '====',
35
            4 => '===',
36
            5 => '==',
37
        ];
38
39
        return $wrapper[$this->level] . ' ' . $this->text . ' ' . $wrapper[$this->level];
40
    }
41
}
42