Skip to content

Commit 75decf6

Browse files
committed
pass markdown to frontMatter
1 parent 62a00e7 commit 75decf6

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/Markdown.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ public function __construct(string $content = '')
4444
/**
4545
* @return array<mixed> [description]
4646
*/
47-
public function frontMatter(): array
47+
public function frontMatter(string $content = ''): array
4848
{
49+
if (strlen($content) === 0) {
50+
$content = $this->content;
51+
}
52+
4953
$frontMatterExtension = new FrontMatterExtension();
5054
return $frontMatterExtension->getFrontMatterParser()->parse(
51-
$this->content . "\n"
55+
$content . "\n"
5256
)->getFrontMatter();
5357
}
5458

@@ -77,14 +81,6 @@ public function convertToHtml(string $content = ''): RenderedContentInterface
7781
return $converter->convertToHtml($this->content());
7882
}
7983

80-
/**
81-
* @deprecated Use `convert()` instead.
82-
*/
83-
public function convertedContent(string $content = ''): string
84-
{
85-
return $this->convert($content);
86-
}
87-
8884
public function convert(string $content = ''): string
8985
{
9086
$html = $this->convertToHtml($content)->getContent();
@@ -106,6 +102,14 @@ public function __toString(): string
106102
return $this->convert();
107103
}
108104

105+
/**
106+
* @deprecated Use `convert()` instead.
107+
*/
108+
public function convertedContent(string $content = ''): string
109+
{
110+
return $this->convert($content);
111+
}
112+
109113
/**
110114
* @return array<mixed> [description]
111115
*/

tests/MarkdownBaselineTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22

33
use Eightfold\Markdown\Markdown;
44

5+
test('Markdown is reusable', function() {
6+
$markdownConverter = Markdown::create()->config([
7+
'html_input' => 'allow',
8+
'allow_unsafe_links' => false
9+
])->minified();
10+
11+
expect(
12+
$markdownConverter->convert()
13+
)->toBe('');
14+
15+
expect(
16+
$markdownConverter->convert('Hello, World!')
17+
)->toBe(<<<html
18+
<p>Hello, World!</p>
19+
html
20+
);
21+
22+
expect(
23+
$markdownConverter->frontMatter(<<<md
24+
---
25+
title: Some title
26+
icon: /path/to/icon alt text
27+
---
28+
md
29+
)
30+
)->toBe([
31+
'title' => 'Some title',
32+
'icon' => '/path/to/icon alt text'
33+
]);
34+
});
35+
536
test('Markdown has multiple ways to approach rendering content', function() {
637
expect(
738
(string) Markdown::create('# Shortest form')

0 commit comments

Comments
 (0)