From f3247c618c497c8271bf19debeec4142edee36da Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 27 May 2022 18:08:46 +0300 Subject: [PATCH] =?UTF-8?q?feat(shortcodes):=20add=20ability=20to=20use=20?= =?UTF-8?q?textile=20directive=20with=20`textile`=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/Parsers/Shortcodes/TextileShortcode.php | 9 +++++++-- .../Parsers/Shortcodes/TextileShortcodeTest.php | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php b/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php index 815c7aee..22b5b720 100644 --- a/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php @@ -20,11 +20,16 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface; use function parsers; // Shortcode: textile -// Usage: (textile) textile text here (/textile) +// Usage: (textile) markdown text here (/textile) +// (textile) markdown text here parsers()->shortcodes()->addHandler('textile', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.textile.enabled')) { return ''; } - return parsers()->textile()->parse(parsers()->shortcodes()->parse($s->getContent())); + if ($s->getContent() != null) { + return parsers()->textile()->parse(parsers()->shortcodes()->parse($s->getContent())); + } + + return '@textile'; }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/TextileShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/TextileShortcodeTest.php index b56ce6d3..e481f4ae 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/TextileShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/TextileShortcodeTest.php @@ -2,7 +2,17 @@ declare(strict_types=1); -test('[textile] shortcode', function () { - $this->assertEquals("

Foo

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

Foo

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

Foo

"); });