1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-09 14:46:53 +02:00

fix(frontmatter): Remove UTF-8 BOM if it exists. And Normalize line endings to Unix style.

This commit is contained in:
Awilum
2020-07-29 21:26:42 +03:00
parent 269fcdbbb0
commit 70b89ed2e1

View File

@@ -101,7 +101,15 @@ class Frontmatter
*/
protected function _decode(string $input)
{
// Remove UTF-8 BOM if it exists.
$input = ltrim($input, "\xef\xbb\xbf");
// Normalize line endings to Unix style.
$input = (string) preg_replace("/(\r\n|\r)/", "\n", $input);
// Parse Frontmatter and Body
$parts = preg_split('/^[\s\r\n]?---[\s\r\n]?$/sm', PHP_EOL . ltrim($input));
if (count($parts) < 3) {
return ['content' => trim($input)];
}