Conditions | 3 |
Paths | 1 |
Total Lines | 23 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | public function process(Page $page, string $output, string $format): string |
||
30 | { |
||
31 | $output = preg_replace_callback( |
||
32 | // https://regex101.com/r/ycWMe4/1 |
||
33 | '/href="(\/|)([A-Za-z0-9_\.\-\/]+)\.md(\#[A-Za-z0-9_\-]+)?"/is', |
||
34 | function ($matches) use ($page) { |
||
35 | // section spage |
||
36 | $hrefPattern = 'href="../%s/%s"'; |
||
37 | // root page |
||
38 | if (empty($page->getFolder())) { |
||
39 | $hrefPattern = 'href="%s/%s"'; |
||
40 | } |
||
41 | // root link |
||
42 | if ($matches[1] == '/') { |
||
43 | $hrefPattern = 'href="/%s/%s"'; |
||
44 | } |
||
45 | |||
46 | return sprintf($hrefPattern, Page::slugify(PrefixSuffix::sub($matches[2])), $matches[3] ?? ''); |
||
47 | }, |
||
48 | $output |
||
49 | ); |
||
50 | |||
51 | return $output; |
||
52 | } |
||
54 |