• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 17038257680

18 Aug 2025 10:41AM UTC coverage: 77.377% (-3.4%) from 80.753%
17038257680

push

github

ArnaudLigny
fix: regex pattern for page front matter parsing

Replaces the previous PATTERN constant with a new regex that allows for more flexible whitespace handling around front matter delimiters. This improves compatibility with various file formats and resolves issues with inconsistent spacing.

2979 of 3850 relevant lines covered (77.38%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.85
/src/Renderer/PostProcessor/MarkdownLink.php
1
<?php
2

3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <arnaud@ligny.fr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Cecil\Renderer\PostProcessor;
15

16
use Cecil\Collection\Page\Page;
17
use Cecil\Collection\Page\PrefixSuffix;
18

19
/**
20
 * MarkdownLink class.
21
 *
22
 * This class processes Markdown links in the output HTML,
23
 * replacing internal links to `.md` files with the correct URLs.
24
 * It handles links that may include a section anchor and adjusts the href attribute accordingly.
25
 */
26
class MarkdownLink extends AbstractPostProcessor
27
{
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * Replaces internal link to *.md files with the right URL.
32
     */
33
    public function process(Page $page, string $output, string $format): string
34
    {
35
        $output = preg_replace_callback(
1✔
36
            // https://regex101.com/r/ycWMe4/1
37
            '/href="(\/|)([A-Za-z0-9_\.\-\/]+)\.md(\#[A-Za-z0-9_\-]+)?"/is',
1✔
38
            function ($matches) use ($page) {
1✔
39
                // section spage
40
                $hrefPattern = 'href="../%s/%s"';
×
41
                // root page
42
                if (empty($page->getFolder())) {
×
43
                    $hrefPattern = 'href="%s/%s"';
×
44
                }
45
                // root link
46
                if ($matches[1] == '/') {
×
47
                    $hrefPattern = 'href="/%s/%s"';
×
48
                }
49

50
                return \sprintf($hrefPattern, Page::slugify(PrefixSuffix::sub($matches[2])), $matches[3] ?? '');
×
51
            },
1✔
52
            $output
1✔
53
        );
1✔
54

55
        return $output;
1✔
56
    }
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc