1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(shortcodes): add ability to use markdown directive with markdown shortcode

This commit is contained in:
Awilum
2022-05-27 17:19:02 +03:00
parent 97e6bda8e0
commit 467758eba8
2 changed files with 19 additions and 4 deletions

View File

@@ -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';
});

View File

@@ -2,7 +2,17 @@
declare(strict_types=1);
test('[markdown] shortcode', function () {
$this->assertEquals("<p><strong>Foo</strong></p>\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("<p><strong>Foo</strong></p>\n", parsers()->shortcodes()->parse('(markdown)**Foo**(/markdown)'));
expect(entries()->create('md', ['test' => '(markdown) **Foo**']))->toBeTrue();
expect(entries()->fetch('md')['test'])->toBe("<p> <strong>Foo</strong></p>");
});