Completed
Push — master ( 50ed96...ddd96c )
by TJ
06:47
created

ParsedownHighlighter::blockAlertComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace sixlive;
4
5
class ParsedownHighlighter extends \Parsedown
6
{
7 1
    public function __construct()
8
    {
9 1
        $this->BlockTypes[':'] = ['Alert'];
10 1
    }
11
12 1
    protected function blockAlert($block)
13
    {
14 1
        if (preg_match('/::: (.*)/', $block['text'], $matches)) {
15
            return [
16 1
                'char' => ':',
17
                'element' => [
18 1
                    'name' => 'div',
19 1
                    'text' => '',
20
                    'attributes' => [
21 1
                        'class' => "alert-{$matches[1]}",
22
                    ],
23
                ],
24
            ];
25
        }
26
    }
27
28 1
    protected function blockAlertContinue($line, $block)
29
    {
30 1
        if (isset($block['complete'])) {
31
            return;
32
        }
33
34 1
        if (preg_match('/:::/', $line['text'], $matches)) {
35 1
            $block['complete'] = true;
36
37 1
            return $block;
38
        }
39
40 1
        $block['element']['text'] .= $line['text']."\n";
41
42 1
        return $block;
43
    }
44
45 1
    protected function blockAlertComplete($block)
46
    {
47 1
        $block['element']['rawHtml'] = $this->text($block['element']['text']);
48 1
        unset($block['element']['text']);
49
50 1
        return $block;
51
    }
52
}
53