Passed
Pull Request — master (#1676)
by Arnaud
10:58 queued 04:17
created

HtmlExcerpt::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Renderer\PostProcessor;
15
16
use Cecil\Collection\Page\Page;
17
18
/**
19
 * HtmlExcerpt class.
20
 *
21
 * Replaces excerpt or break tag by HTML anchor.
22
 */
23
class HtmlExcerpt extends AbstractPostProcessor
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function process(Page $page, string $output, string $format): string
29
    {
30 1
        if ($format == 'html') {
31
            // https://regex101.com/r/Xl7d5I/3
32 1
            $pattern = '(.*)(<!--[[:blank:]]?(excerpt|break)[[:blank:]]?-->)(.*)';
33 1
            $replacement = '$1<span id="more"></span>$4';
34 1
            $excerpt = preg_replace('/' . $pattern . '/is', $replacement, $output, 1);
35 1
            $output = $excerpt ?? $output;
36
        }
37
38 1
        return $output;
39
    }
40
}
41