I’ve adjusted a code example, as suggested by @texnixe, to replace some custom tags instead of using <div markdown="1" class="some-class">
which is great and indeed much more user friendly.
Now I’m making some code examples which obviously only display properly when I use some extra space. How can I prevent replacement when tags are wrapped in (or start) with ~~~
.
It’s a bit silly to add notes with every example to omit extra whitespace
'hooks' => [
'kirbytags:before' => [
function (string $text = null, array $data = []) {
return preg_replace_callback('!<(warning|info|box|inline)>(.*)<\/(warning|info|box|inline)>!siU', function (array $matches) use ($data) {
$type = $matches[1];
$block = '<div class="' . $type . '" markdown="1">';
$block .= $this->kirbytext($matches[2], $data);
$block .= '</div>';
return $block;
}, $text);
},
]
]
Code example with extra whitespace to prevent replacement:
<box >
Display text in a box.
</box >