Header::rule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php # -*- coding: utf-8 -*-
2
declare(strict_types=1);
3
4
namespace Bueltge\Marksimple\Rule;
5
6
class Header extends AbstractRegexRule
7
{
8
9
    /**
10
     * Get the regex rule to identify the fromFile for the callback.
11
     * Header h1 - h6.
12
     *
13
     * @return string
14
     */
15 12
    public function rule(): string
16 12
    {
17 12
        return '#^(\#{1,6})\s*([^\#]+?)\s*\#*$#m';
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 9
    public function render(array $content): string
24 9
    {
25 9
        $headingLevel = \strlen($content[1]);
26 9
        $header = trim($content[2]);
27
        // Build anker without space, numbers.
28 9
        $anker = preg_replace('#[^a-z?!]#', '', strtolower($header));
29
30 9
        return sprintf('<h%d id="%s">%s</h%d>', $headingLevel, $anker, $header, $headingLevel);
31
    }
32
}
33