Skip to content

Commit

Permalink
pass markdown to frontMatter
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbruce committed Oct 16, 2021
1 parent 62a00e7 commit 75decf6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public function __construct(string $content = '')
/**
* @return array<mixed> [description]
*/
public function frontMatter(): array
public function frontMatter(string $content = ''): array
{
if (strlen($content) === 0) {
$content = $this->content;
}

$frontMatterExtension = new FrontMatterExtension();
return $frontMatterExtension->getFrontMatterParser()->parse(
$this->content . "\n"
$content . "\n"
)->getFrontMatter();
}

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

/**
* @deprecated Use `convert()` instead.
*/
public function convertedContent(string $content = ''): string
{
return $this->convert($content);
}

public function convert(string $content = ''): string
{
$html = $this->convertToHtml($content)->getContent();
Expand All @@ -106,6 +102,14 @@ public function __toString(): string
return $this->convert();
}

/**
* @deprecated Use `convert()` instead.
*/
public function convertedContent(string $content = ''): string
{
return $this->convert($content);
}

/**
* @return array<mixed> [description]
*/
Expand Down
31 changes: 31 additions & 0 deletions tests/MarkdownBaselineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

use Eightfold\Markdown\Markdown;

test('Markdown is reusable', function() {
$markdownConverter = Markdown::create()->config([
'html_input' => 'allow',
'allow_unsafe_links' => false
])->minified();

expect(
$markdownConverter->convert()
)->toBe('');

expect(
$markdownConverter->convert('Hello, World!')
)->toBe(<<<html
<p>Hello, World!</p>
html
);

expect(
$markdownConverter->frontMatter(<<<md
---
title: Some title
icon: /path/to/icon alt text
---
md
)
)->toBe([
'title' => 'Some title',
'icon' => '/path/to/icon alt text'
]);
});

test('Markdown has multiple ways to approach rendering content', function() {
expect(
(string) Markdown::create('# Shortest form')
Expand Down

0 comments on commit 75decf6

Please sign in to comment.