diff --git a/src/Highlighter.php b/src/Highlighter.php
index 9b6bee9..e59e3bb 100644
--- a/src/Highlighter.php
+++ b/src/Highlighter.php
@@ -93,6 +93,8 @@ public function parse(string $content, string|Language $language): string
$this->currentLanguage = $language;
+ $content = $this->normalizeNewline($content);
+
return $this->parseContent($content, $language);
}
@@ -198,4 +200,9 @@ private function getAfterInjections(Language $language): Generator
yield $this->gutterInjection;
}
}
+
+ private function normalizeNewline(string $subject): string
+ {
+ return preg_replace('~\R~u', "\n", $subject);
+ }
}
diff --git a/tests/HighlighterTest.php b/tests/HighlighterTest.php
index 0d142bf..398c2c2 100644
--- a/tests/HighlighterTest.php
+++ b/tests/HighlighterTest.php
@@ -56,6 +56,7 @@ public static function data(): array
return [
['01', 'php'], // general
['02', 'html'], // deep injections
+ ['03', 'php'], // windows line endings
];
}
}
diff --git a/tests/stubs/03.txt b/tests/stubs/03.txt
new file mode 100644
index 0000000..61d9f66
--- /dev/null
+++ b/tests/stubs/03.txt
@@ -0,0 +1,37 @@
+// controller for home
+final readonly class HomeController
+{
+ #[Get(uri: '/home')]
+ public function __invoke(): View
+ {
+ return view('Views/home.view.php')
+ ->data(
+ name: 'Brent',
+ date: new DateTime(),
+ );
+ }
+
+ #[Post(uri: '/home')]
+ public function __invoke(): View
+ {
+ }
+}
+===
+
+final readonly class HomeController
+{
+ #[Get(uri: '/home')]
+ public function __invoke(): View
+ {
+ return view('Views/home.view.php')
+ ->data(
+ name: 'Brent',
+ date: new DateTime(),
+ );
+ }
+
+ #[Post(uri: '/home')]
+ public function __invoke(): View
+ {
+ }
+}