Markdown=1 and multiple kirby-tag image

pasting following code into the panel field parsed by kirbytext() only outputs code for figure.img[src=a.jpg] and b.jpg does not appear at all. any ideas how to fix this?

<div markdown=1>
(image: a.jpg)
(image: b.jpg)

i need the markdown=1 flag since the code from the div is actually created by a custom tag. that tag should be able to contain other tags. something like @texnixe’s columns.

(mytag: start)
(image: a.jpg)
(image: b.jpg)
(mytag: end)

results in

<div markdown=1>
(image: a.jpg)
(image: b.jpg)

did forget… documentation for markdown=1 from markdown extra.

Have you enabled markdown.extra in your config? It seems to work if it is not enabled.

i do have c::set('markdown.extra', true); and i need it since there can be markdown within the content (like with your columns plugin).

(mytag: start)
## headline
(image: a.jpg)
(image: b.jpg)

- liste a
- liste b

(mytag: end)

I see. How about using the official columns plugin as a starting point?

The columns tag is actually not my plugin … it’s something I copied from @NECKRHINOS for testing ages ago …

that plugin needs a newline after the (columns…), right? which might be error prone and/or cause confusion for my client. as far as i can see it uses regex… which i am not very good at (yet).

but i will give it a try and report back.

I’ve always found this site helpful when dealing with regex; I’m not good at it either (yet) :slight_smile:

using that one too, but that expression i still do not get.


i tried to implement the same code like the original kirby textsnippets, no regex, just replacing. problem is still there. maybe markdown.extra and kirbytext() do not play well together.

i just found out how to make it work. adding spaces or newline.

with markdown extra active you need to have extra space or a newline after first kirbytag image, and it works. so maybe the markdown extra is confusing the regex of kirbytext()?

I would definitely use something like the in the columns plugin. It’s just way more robust.


You can use this regular expression for your usecase:

!\(mytag: start\)(.*?)\(mytag: end\)!is

It will match everything between your start and end tags and $matches[2] in the callback will then contain the content between the tags.

maybe i will give simple regex a try to improve my regex skillz :wink:

But then you first have to learn another language just to come up with some regex :pensive:, I don’t really know if that makes it easier?

But maybe it’s worth it for more complicated stuff. Thanks for sharing, anyway.

hehe. maybe but they have a php7 wrapper using functions with is a bit like kirbys filtering or kirby toolkits db query functions, right?

$query = SRL::startsWith()
->anyOf(function (Builder $query) {
->anyOf(function (Builder $query) {
1 Like

i can not see why using akirbytext::$pre[] function should be better than a tag. both are regex based (preg_replace_callback) and executed right after each other. tags just provide easier access to attributes.

still tags fail where the kirbytext::$pre works. so i want to find out why.

what are the ! and !is in the preg_replace_callback for anyway?

$text = preg_replace_callback('!(?=[^\]])\([a-z0-9_-]+:.*?\)!is', array($this, 'tag'), $text);

i created a tag version of columns it fails as well. the h2 is not parsed. no markdown is parsed at all.

content in page object

(columns: start)
## headline
(image: a.jpg)
(image: b.jpg)
(columns: umbruch)
(image: b.jpg)
some text
(columns: ende)

tag code

kirbytext::$tags['columns'] = array(
  'attr' => array(), // omitted for example
  'html' => function($tag) {

    $z = str::lower($tag->attr('columns'));
    if(in_array($z, ['start']))
      return "<div class='row'><div class='col'>";
    else if (in_array($z, ['umbruch']))
      return "</div><div class='col'>";
    else if (in_array($z, ['ende']))
      return "</div></div>";

    return ''; // just remove invalid

and because no markdown is parse i initially applied markdown=1 to the div.col as a fix. but that caused the second kirby-tag image to disappear.

ah. @bastianallgeier’s column plugin is creating a field for content within the columns the and calling kirbytext() again. thats why the images are parsed correctly.

but then again i do not understand how @texnixe old plugin was able to support markdown. :frowning:

SUMMARY: so one can not use tags to create unclosed html elements, right?

As I said, it was not my tag and as far as I remember I copied it for testing from @NECKRHINOS because of a similar issue which was never resolved. I should just delete it.

Yep, that’s true.

If you look closely at the columns plugin, you see that it doesn’t return start and end tags separately but matches the whole column block and parses the content using Kirbytext itself.

As you wrote and Sonja confirmed, tags are not meant to return incomplete HTML, they can only return HTML that is properly closed.

The point of the Kirbytext pre filter is to match more than just individual tags. If you just plug the regular expression that I proposed above into the columns plugin and modify the callback function according to your needs, it should be fine. Don’t try to return incomplete HTML from the filter either, it won’t work.

The exclamation marks are the open and close characters (you could use slashes instead if you want). is means “case insensitive” and “singleline” (= the regex works with newlines in the matched text).