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