From 467758eba846826bb12b255aa338a7a1e0d6e235 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 27 May 2022 17:19:02 +0300 Subject: [PATCH] feat(shortcodes): add ability to use markdown directive with `markdown` shortcode --- .../Parsers/Shortcodes/MarkdownShortcode.php | 7 ++++++- .../Parsers/Shortcodes/MarkdownShortcodeTest.php | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php b/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php index fa4b27fc..83267429 100644 --- a/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php @@ -21,10 +21,15 @@ use function parsers; // Shortcode: markdown // Usage: (markdown) markdown text here (/markdown) +// (markdown) markdown text here parsers()->shortcodes()->addHandler('markdown', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.markdown.enabled')) { return ''; } - return parsers()->markdown()->parse(parsers()->shortcodes()->parse($s->getContent())); + if ($s->getContent() != null) { + return parsers()->markdown()->parse(parsers()->shortcodes()->parse($s->getContent())); + } + + return '@markdown'; }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php index d9b46303..f299046d 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php @@ -2,7 +2,17 @@ declare(strict_types=1); -test('[markdown] shortcode', function () { - $this->assertEquals("

Foo

\n", - parsers()->shortcodes()->parse('(markdown)**Foo**(/markdown)')); +beforeEach(function() { + filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true); +}); + +afterEach(function () { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('markdown shortcode', function () { + $this->assertEquals("

Foo

\n", parsers()->shortcodes()->parse('(markdown)**Foo**(/markdown)')); + + expect(entries()->create('md', ['test' => '(markdown) **Foo**']))->toBeTrue(); + expect(entries()->fetch('md')['test'])->toBe("

Foo

"); });