Kirbytags Parenthesis Issue

Hi fellow Kirbies!

I know there are two posts on this topic already, but none helped me fix my problem.
I am currently working on a website on regular expression and how to learn them. For that I have built a Kirbytag where I can put my grep code into and it generates a code element for me. It looks like this:

(grep: \([^)]+\))

The issue here is, that the code gets cut off at this point \([^)]+\. I understand, that the second-to-last closing parenthesis is closing the tag, leaving the very last outside its boundary. Is there a way to fix this? I read about Kirbyhooks but I am not quite sure on how I would make this work.

Any help is much appreciated.

Enjoy the weekend,
Jannis

Which Kirby version are you using? Parenthesis are allowed in Kirbytags since Kirby 3.4.0.

I am using 3.4.0.


This is my plugin code for the tag:

<?php
Kirby::plugin('grep/grep', [
  'tags' => [
    'grep' => [
      'html' => function ($tag) {
        return '<pre class="language-regex"><code class="language-regex">' . $tag->value . '</code></pre>';
      }
    ]
  ]
]);

What’s weird is, that it works for other cases. For example (grep: \b(\d{1,2})(\.)(\d{1,2})(\.)(\d{4}|\d{2})\b) does not produce any problems.

Does it have to do with the amount of parenthesis maybe?

Well, yes, probably, because you have one β€œextra” closing parenthesis in your pattern. So this is probably one of those edge cases that were to be expected.

Maybe it would be better not to use a Kirbytag but a Kirbytext filter for this use case.

Can you explain how that would work? Is there a tutorial that explains what a Kirbytext filter is or how it works? I am pretty new to coding and kirby cms :upside_down_face:

Also, I can’t seem to find anything in the reference … Thank you @texnixe for the help already!


With these hooks, you can basically replace anything in Kirbytext. You can also find the gallery example in the Starterkit that uses double curly braces or the different boxes in the getkirby.com repo:


1 Like

I will have a look into it. Thank you so much!

For anyone who reads this in the future: A way to fix the issue is to use the HTML-Entity for the closing parenthesis. Not ideal but it gets the job done. My Kirbytag now looks like this:

(grep: \([^)]+\&#x29;)