Maximum function nesting level of '256' reached, aborting!

Working accordion replacement code, (this places the accordion on the right spot in the text):

<?php

Kirby::plugin('kirby/accordion', [
    'hooks' => [
        'kirbytags:after' => function ($text, $data) {

            return preg_replace_callback('!{{ accordion }}!siU', function($match) use ($data) {
                
                if ($items = $data['parent']->accordion()->toStructure()) {
                    $block = snippet('accordion', ['items' => $items], true);
                } else {
                    $block = '';
                }
                return $block;

            }, $text);
           
        }
    ]
]);

Note: kirbytags:after