# Markdown=1 and multiple kirby-tag image

**URL:** <https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 4, 2016, 1:36pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179 "2016-09-04T13:36:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 1:36pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/1 "2016-09-04T13:36:44Z")

</div>

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)
</div>

```

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](https://github.com/texnixe/kirbytext-columns).

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 1:39pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/2 "2016-09-04T13:39:22Z")

</div>

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

```

results in

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

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 2:08pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/3 "2016-09-04T14:08:48Z")

</div>

did forget… documentation for markdown=1 from [markdown extra](https://michelf.ca/projects/php-markdown/extra/#markdown-attr).

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 4, 2016, 2:23pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/4 "2016-09-04T14:23:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 2:41pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/5 "2016-09-04T14:41:55Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 4, 2016, 3:10pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/6 "2016-09-04T15:10:30Z")

</div>

I see. How about using the [official columns plugin](https://github.com/getkirby-plugins/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 …

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 3:15pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/7 "2016-09-04T15:15:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 4, 2016, 3:16pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/8 "2016-09-04T15:16:55Z")

</div>

I’ve always found [this site](http://regexr.com/) helpful when dealing with regex; I’m not good at it either (yet) 🙂

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 3:18pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/9 "2016-09-04T15:18:30Z")

</div>

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

```
!\(columns(…|\.{3})\)(.*?)\((…|\.{3})columns\)!is

```

> <https://github.com/getkirby-plugins/columns-plugin/blob/master/columns.php#L11>

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 3:32pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/10 "2016-09-04T15:32:00Z")

</div>

> [@bnomei](#):
>
> kirbytext::$pre

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.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 4, 2016, 3:42pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/11 "2016-09-04T15:42:44Z")

</div>

> [@bnomei](#):
>
> (mytag: start)
> 
> ## headline
> 
> (image: a.jpg) \<!-- one space at end or a blank line after  
> (image: b.jpg) \<!-- or one space before
> 
> - liste a
> - liste b
> 
> (mytag: end)

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()?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 4, 2016, 6:58pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/12 "2016-09-04T18:58:43Z")

</div>

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

Regarding:

> [@bnomei](#):
>
> using that one too, but that expression i still do not get.
> 
> `!\(columns(…|\.{3})\)(.*?)\((…|\.{3})columns\)!is`

You can use this regular expression for your usecase:

```auto
!\(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.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 5, 2016, 9:56am UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/13 "2016-09-05T09:56:19Z")

</div>

maybe i will give [simple regex](https://simple-regex.com/) a try to improve my regex skillz 😉

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 5, 2016, 10:00am UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/14 "2016-09-05T10:00:24Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 5, 2016, 10:10am UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/15 "2016-09-05T10:10:37Z")

</div>

hehe. maybe but they have a [php7 wrapper](https://github.com/SimpleRegex/SRL-PHP) using functions with is a bit like kirbys filtering or [kirby toolkits db query functions](https://getkirby.com/docs/toolkit/api#database-query), right?

```
$query = SRL::startsWith()
->anyOf(function (Builder $query) {
    $query->digit()
        ->letter()
        ->oneOf('._%+-');
})->onceOrMore()
->literally('@')
->anyOf(function (Builder $query) {
    $query->digit()
        ->letter()
        ->oneOf('.-');
})->onceOrMore()
->literally('.')
->letter()->atLeast(2)
->mustEnd()->caseInsensitive();
```

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 5, 2016, 10:59am UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/16 "2016-09-05T10:59:02Z")

</div>

i can not see why using a`kirbytext::$pre[]` function should be better than a tag. both are regex based (`preg_replace_callback`) and executed [right after each other](https://github.com/getkirby/kirby/blob/master/core/kirbytext.php#L49). 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);

```

**TESTCASES**  
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)
text
(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
  }
);
```

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 5, 2016, 11:02am UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/17 "2016-09-05T11:02:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [September 5, 2016, 12:38pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/18 "2016-09-05T12:38:06Z")

</div>

ah. @bastianallgeier’s column plugin is [creating a field for content within the columns the and calling kirbytext()](https://github.com/getkirby-plugins/columns-plugin/blob/master/columns.php#L18) again. thats why the images are parsed correctly.

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

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 5, 2016, 12:42pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/19 "2016-09-05T12:42:44Z")

</div>

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.

> [@bnomei](#):
>
> SUMMARY: so one can not use tags to create unclosed html elements, right?

Yep, that’s true.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 5, 2016, 1:10pm UTC](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179/20 "2016-09-05T13:10:20Z")

</div>

> [@bnomei](#):
>
> 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.

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.

> [@bnomei](#):
>
> what are the ! and !is in the preg\_replace\_callback for anyway?

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

[Next page](https://forum.getkirby.com/t/markdown-1-and-multiple-kirby-tag-image/5179.md?page=2)
