Conditions | 3 |
Paths | 1 |
Total Lines | 23 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 3.7085 |
Changes | 0 |
1 | <?php |
||
33 | 1 | public function process(Page $page, string $output, string $format): string |
|
34 | { |
||
35 | 1 | $output = preg_replace_callback( |
|
36 | // https://regex101.com/r/ycWMe4/1 |
||
37 | 1 | '/href="(\/|)([A-Za-z0-9_\.\-\/]+)\.md(\#[A-Za-z0-9_\-]+)?"/is', |
|
38 | 1 | function ($matches) use ($page) { |
|
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 | 1 | $output |
|
53 | 1 | ); |
|
54 | |||
55 | 1 | return $output; |
|
56 | } |
||
58 |