diff --git a/src/ComplexMarkdownParser.php b/src/ComplexMarkdownParser.php index a2f37dd..07a67c1 100644 --- a/src/ComplexMarkdownParser.php +++ b/src/ComplexMarkdownParser.php @@ -84,7 +84,7 @@ protected function getBody(): string protected function trimBody(array $body): array { - if (trim($body[0]) === '') { + if (isset($body[0]) && trim($body[0]) === '') { unset($body[0]); } diff --git a/tests/YamlFrontMatterMarkdownCompatibleParseTest.php b/tests/YamlFrontMatterMarkdownCompatibleParseTest.php index 5088d04..62706e7 100644 --- a/tests/YamlFrontMatterMarkdownCompatibleParseTest.php +++ b/tests/YamlFrontMatterMarkdownCompatibleParseTest.php @@ -51,7 +51,7 @@ public function it_separates_the_front_matter_from_the_body() public function it_leaves_string_without_front_matter_intact() { $document = YamlFrontMatter::markdownCompatibleParse( - "Lorem ipsum." + 'Lorem ipsum.' ); $this->assertInstanceOf(Document::class, $document); @@ -97,4 +97,16 @@ public function it_can_parse_a_string_with_windows_line_endings() $this->assertEquals(['foo' => 'bar'], $document->matter()); $this->assertStringContainsString('Lorem ipsum.', $document->body()); } + + /** @test */ + public function it_can_parse_markdown_file_with_front_matter_and_no_markdown_body() + { + $document = YamlFrontMatter::markdownCompatibleParse( + "---\nfoo: bar\n---" + ); + + $this->assertInstanceOf(Document::class, $document); + $this->assertEquals(['foo' => 'bar'], $document->matter()); + $this->assertEmpty($document->body()); + } }