Simple plugin to wrap content in div with class

Hello all,

I’m making a simple plugin to wrap some text in a field in my content page, inside a div with a certain class. So, in the page field it looks like this:

(checklist: text:
# Title
Some text
)

And the plugin is as follows:

<?php

Kirby::plugin('plugin/checklist', [
  'tags' => [
    'checklist' => [
      'attr' => [
        'text'
      ],
      'html' => function($tag) {

        return '<div class="checklist">' . $tag->text . '</div>';

      }
    ]
  ]
]);

So far it’s working, but the problem is the ouput is rendering the markdown as it is, and not replacing # for the heading tags for example. I’ve been playing with adding text()->kt() as it works on the templates, but I haven’t managed to do the same in the plugin…

Since kt() is a field method (and as such requires a field object), you cannot call this method on a string. However, Kirby has the kirbytext() helper you can use here:

kirbytext($tag->text)

I’m not sure that using multiline text within a Kirbytag is such a great idea though. I think you’d be better of with a kirbytag hook.

You can find examples here: https://github.com/getkirby/getkirby.com/blob/master/site/plugins/maki/hooks.php

Usage example of the info tag:

<info>
This is a paragraph.

Here comes another one.

## And this is a headline
And some more text
</info>

Another option is this plugin: https://github.com/yoanmalie/kirbytextWrap

Thanks, @bvdputte, I knew it was there but couldn’t find the plugin. If I see this correctly, though, it will replace all p’s from the text and use another wrapper instead?

Thanks! This works; I’ll use it as a workaround until I can research and learn how hooks work. The info box is a good example that I can adapt to my needs.