Kirbytext/markdown without p-Element

I have something like this:


which of cause renders into something this:

<span><p>Lorem <a href="#">Ispum</a></p></span>

but I want something like this (without the p-Element)

<span>Lorem <a href="#">Ispum</a></span>

I tried to create a new field method, which would be fine. But I don’t know how to convert (link: # text: Lorem) to <a href="#">Lorem</a>.

Any smart ideas for this?

You could try checking out this page. I haven’t tested it though.

1 Like

That’s exactly what I’ve been looking for.

I just had to make a small adjustment.
This line throws an error (Call to undefined method Kirbytext::init())

$text = kirbytext::init($text, true);


$text = kirbytext($text);

works all fine.

Thanks @Luke.

I had this problem too. Sometimes it is necessary to control the surrounding <p> tags by your own, but keep that the kirbytext is pared as it used to be.
I had also used kirbytestSans.php at first, but there were some Problems with kirby 2, so I changed some things and made a separate git repository:

The big problem for me was, that kirbytextSans has complications if there are several paragraphs in the text, so my plugin does only remove the first opening and last closing paragraph tag.


Don’t like to bump topics, but I think this can be useful.
We only want to remove the first and last p tag from kirbytext, right? I always use a custom field method for this:

field::$methods['kirbytextSans'] = function($field) {
  return str::substr(kirbytext($field->value), 3, -4);

No regex! :stuck_out_tongue_winking_eye:


Since Kirby v3.1.0 you can use $field->kirbytextinline(). More on that here.