|
17 | 17 | use Symfony\Component\Filesystem\Filesystem;
|
18 | 18 | use Symfony\Component\Finder\Finder;
|
19 | 19 | use SymfonyDocsBuilder\BuildContext;
|
| 20 | +use function Symfony\Component\String\u; |
20 | 21 |
|
21 | 22 | class HtmlForPdfGenerator
|
22 | 23 | {
|
@@ -100,12 +101,13 @@ private function fixInternalUrls(string $fileContent, string $dir): string
|
100 | 101 | return preg_replace_callback(
|
101 | 102 | '/href="([^"]+?)"/',
|
102 | 103 | static function ($matches) use ($dir) {
|
103 |
| - if ('http' === substr($matches[1], 0, 4) || '#' === substr($matches[1], 0, 1)) { |
| 104 | + if (u($matches[1])->startsWith(['http', '#'])) { |
104 | 105 | return $matches[0];
|
105 | 106 | }
|
106 | 107 |
|
107 | 108 | $path = [];
|
108 |
| - foreach (explode('/', $dir.'/'.str_replace(['.html', '#'], ['', '-'], $matches[1])) as $part) { |
| 109 | + foreach (u($matches[1])->replace('.html', '')->replace('#', '-')->split('/') as $urlPart) { |
| 110 | + $part = $urlPart->toString(); |
109 | 111 | if ('..' === $part) {
|
110 | 112 | array_pop($path);
|
111 | 113 | } else {
|
@@ -146,7 +148,7 @@ private function cleanupContent($content)
|
146 | 148 | $content = preg_replace_callback(
|
147 | 149 | '#<a href="(.*?)" class="reference external"(?:[^>]*)>(.*?)</a>#',
|
148 | 150 | static function ($matches): string {
|
149 |
| - if (0 === strpos($matches[2], 'http')) { |
| 151 | + if (u($matches[2])->startsWith('http')) { |
150 | 152 | return sprintf('<em><a href="%s">%s</a></em>', $matches[2], $matches[2]);
|
151 | 153 | }
|
152 | 154 |
|
|
0 commit comments