diff --git a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php index 09748213..8e48271a 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -20,19 +20,23 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface; use function parsers; use function registry; -// Shortcode: [strings] strings to modify [/strings] +// Shortcode: strings +// Usage: (strings) strings to modify (/strings) parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.strings.enabled')) { return ''; } - $content = $s->getContent(); - $varsDelimeter = $s->getParameter('varsDelimeter') ?: ','; + $content = ($s->getContent() != null) ? parsers()->shortcodes()->parse($s->getContent()) : ''; + $varsDelimeter = ($s->getParameter('varsDelimeter') != null) ? parsers()->shortcodes()->parse($s->getParameter('varsDelimeter')) : ','; foreach($s->getParameters() as $key => $value) { $vars = $value !== null ? strings($value)->contains($varsDelimeter) ? explode($varsDelimeter, $value) : [$value] : []; + // Parse shortcodes for each var. + $vars = array_map(fn($v) => parsers()->shortcodes()->parse(is_string($v) ? $v : ''), $vars); + if ($key == 'append') { if (is_iterable($vars)) { $content = strings($content)->{'append'}(...$vars)->toString(); diff --git a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php index 8e1b2416..93fb6c17 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -test('(strings) shortcode', function () { +test('strings shortcode', function () { // lower $this->assertEquals("zed foo bar", parsers()->shortcodes()->parse("(strings lower)zed foo bar(/strings)")); @@ -340,4 +340,8 @@ test('(strings) shortcode', function () { // wordsFrequency $this->assertEquals('{"foo":"33.33","bar":"33.33","baz":"33.33"}', parsers()->shortcodes()->parse("(strings wordsFrequency)foo bar baz(/strings)")); +}); + +test('strings nested shortcode', function () { + expect(parsers()->shortcodes()->parse("(strings append:'(strings hash)(strings random:10 /)(/strings)')Hash: (/strings)"))->toBe('Hash: 66e51cf9114bf1eef8f1793ad1c0e8a1'); }); \ No newline at end of file