Completed
Push — master ( 3ddc1a...505196 )
by Vladimir
02:20
created

MarkdownEngine::blockHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 1
rs 9.4285
1
<?php
2
3
namespace allejo\stakx\Engines;
4
5
use Highlight\Highlighter;
6
7
class MarkdownEngine extends \Parsedown
8
{
9
    protected $highlighter;
10
11 1
    public function __construct ()
12
    {
13 1
        $this->highlighter = new Highlighter();
14 1
    }
15
16 1
    protected function blockHeader($Line)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $Line is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
17
    {
18 1
        $Block = parent::blockHeader($Line);
19
20
        // Create our unique ids by sanitizing the header content
21 1
        $id = strtolower($Block['element']['text']);
22 1
        $id = str_replace(' ', '-', $id);
23 1
        $id = preg_replace('/[^0-9a-zA-Z-_]/', '', $id);
24 1
        $id = preg_replace('/-+/', '-', $id);
25
26 1
        $Block['element']['attributes']['id'] = $id;
27
28 1
        return $Block;
29
    }
30
31
    public function blockFencedCodeComplete ($block)
32
    {
33
        // The class has a `language-` prefix, remove this to get the language
34
        if (isset($block['element']['text']['attributes']))
35
        {
36
            $language = substr($block['element']['text']['attributes']['class'], 9);
37
38
            try
39
            {
40
                $highlighted = $this->highlighter->highlight($language, $block['element']['text']['text']);
41
                $block['element']['text']['text'] = $highlighted->value;
42
            }
43
            catch (\DomainException $exception) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
44
        }
45
46
        return $block;
47
    }
48
}