From e3e077727b2589ae9308c27da7836b29535159ea Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 5 May 2022 07:10:28 +0300 Subject: [PATCH] feat(shortcodes): `[strings]` shortcode - add `chars` modifier --- src/flextype/core/Parsers/Shortcodes/StringsShortcode.php | 4 ++++ .../flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php index 45d1f43c..249db0dd 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -104,6 +104,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if ($key == 'capitalize') { $content = strings($content)->{'capitalize'}()->toString(); } + + if ($key == 'chars') { + $content = serializers()->json()->encode(strings($content)->{'chars'}()); + } } return (string) $content; diff --git a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php index a8dc516f..d3cfdafb 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php @@ -55,4 +55,7 @@ test('[strings] shortcode', function () { // capitalize $this->assertEquals("That Country Was At The Same Stage Of Development As The United States In The 1940S", parsers()->shortcodes()->parse('[strings capitalize]that country was at the same stage of development as the United States in the 1940s[/strings]')); + // chars + $this->assertEquals('["c","a","r","_","f","ò","ô","_","b","à","ř","s","_","a","p","p","l","e"]', parsers()->shortcodes()->parse('[strings chars]car_fòô_bàřs_apple[/strings]')); + }); \ No newline at end of file