How to render a snippet inside a custom KirbyTag without `<pre>` tags appearing?

That was my assumption as well. But you can make use of the kirbytext:before and kirbytext:after hooks to overcome this issue.

'hooks' => [
    'kirbytext:before' => function ($text) {
        $tags = [
            'article',
        ];

        return preg_replace_callback('!\((' . implode('|', $tags) . ')+:.*?\)!is', function ($match) {
            return '<!--' . substr($match[0], 1, -1) . '-->';
        }, $text);
    },
    'kirbytext:after' => function ($text) {
        $tags = [
            'article',
        ];

        return preg_replace_callback('!<\!--(' . implode('|', $tags) . ')+:.*?-->!is', function ($match) {
            return kirbytags('(' . substr($match[0], 4, -3) . ')');
        }, $text);
    },
]
1 Like