From 75decf68c989647101286dacfcd4515a41c55bf8 Mon Sep 17 00:00:00 2001
From: Josh Bruce
Date: Sat, 16 Oct 2021 13:20:29 -0500
Subject: [PATCH] pass markdown to frontMatter
---
src/Markdown.php | 24 ++++++++++++++----------
tests/MarkdownBaselineTest.php | 31 +++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/src/Markdown.php b/src/Markdown.php
index 3b44679..b17bd00 100644
--- a/src/Markdown.php
+++ b/src/Markdown.php
@@ -44,11 +44,15 @@ public function __construct(string $content = '')
/**
* @return array [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();
}
@@ -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();
@@ -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 [description]
*/
diff --git a/tests/MarkdownBaselineTest.php b/tests/MarkdownBaselineTest.php
index 708789e..965212d 100644
--- a/tests/MarkdownBaselineTest.php
+++ b/tests/MarkdownBaselineTest.php
@@ -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(<<Hello, World!
+ html
+ );
+
+ expect(
+ $markdownConverter->frontMatter(<<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')