# No markdown parsing with kirbytags

**URL:** <https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 23, 2015, 9:20am UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070 "2015-09-23T09:20:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![a-v-l](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/a-v-l/32/962_2.png) [@a-v-l](https://forum.getkirby.com/u/a-v-l)\
**Post date:** [September 23, 2015, 9:20am UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070/1 "2015-09-23T09:20:59Z")

</div>

Not sure if this is an issue or just me doing it the wrong way…

I want to use Kirbytags to offer a simple-to-use accordion within the content section:

```
kirbytext::$tags['accordion'] = array(
  'attr' => array(
    'title'
  ),
  'html' => function($tag) {
    switch ($tag->attr('accordion')) {
      case 'open':
        $markup = '<section class="accordion"><header class="accordion-header">';
        $markup .= $tag->attr('title');
        $markup .= '</header><div class="accordion-content">';
        break;
      case 'close':
        $markup = '</div></section>';
        break;
    }
    return $markup;
  }
);

```

In the content section (in the panel) this would be used like this:

```
(accordion: open title: My accordion title )
Lorem **fat impsum** dolor…
(accordion: close)

```

the problem is that `Lorem **fat impsum** dolor…` will not be outputted as HTML but as plaintext (including the asterisks). I think this is due to the opening HTML tags `<section>` and `<div>` – because closing them in `(accordion: open…)` solves the problem (but of course makes no sense).

_Any ideas on this?_

---

<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 23, 2015, 9:39am UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070/2 "2015-09-23T09:39:50Z")

</div>

That’s a general problem with Markdown. HTML block tags prevent parsing of Markdown inside them.

For more complex tags like yours, it makes sense to implement a pre-filter instead. See the [columns](https://github.com/getkirby/plugins/blob/master/columns/columns.php) plugin for an example. It matches a set of two column tags (one opening and one closing one) and replaces them with custom HTML and the HTML representation of the Kirbytext inside the tags.

---

<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 23, 2015, 9:53am UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070/3 "2015-09-23T09:53:24Z")

</div>

Markdown inside html block tags is supported in parsedown extra ([https://github.com/erusev/parsedown-extra/issues/14](https://github.com/erusev/parsedown-extra/issues/14)). If you enable Markdown Extra in your config.php

```php
c::set('markdown.extra', true);

```

and change your tag code like this (i.e. add `markdown="1"` to your inner html tag):

```php
<?php
kirbytext::$tags['accordion'] = array(
  'attr' => array(
    'title'
  ),
  'html' => function($tag) {
    switch ($tag->attr('accordion')) {
      case 'open':
        $markup = '<section class="accordion"><header class="accordion-header" ';
        $markup .= $tag->attr('title');
        $markup .= '</header><div class="accordion-content" markdown="1">>';
        break;
      case 'close':
        $markup = '</div></section>';
        break;
    }
    return $markup;
  }
);

```

your code should work.

---

<div class="post-metadata">

**Author:** ![a-v-l](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/a-v-l/32/962_2.png) [@a-v-l](https://forum.getkirby.com/u/a-v-l)\
**Post date:** [September 23, 2015, 10:01am UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070/4 "2015-09-23T10:01:58Z")

</div>

Thank you for providing the two solutions!

For bigger projects I guess the plugin would be the more performant solution. But in my case I will go for `markdown.extra` – which is such a no-brainer!

**Thanks**

---

<div class="post-metadata">

**Author:** ![fanningert](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fanningert/32/141_2.png) [@fanningert](https://forum.getkirby.com/u/fanningert)\
**Post date:** [September 24, 2015, 5:08am UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070/5 "2015-09-24T05:08:03Z")

</div>

@a-v-l  
I wrote a plugin what can help you with your problem.

> **[fanningert/kirbycms-extension-webhelper](https://github.com/fanningert/kirbycms-extension-webhelper)**
>
> kirbycms-extension-webhelper - A collection of little helper for usage in Kirby

With this plugin you can easy create tag with a begin and end tag, like…

```auto
(accordion title: My accordion title )
Lorem **fat impsum** dolor…
(/accordion)

```

kirbytext and markdown work in the tag body. As usage example, you can use the messagebox tag in the same plugin.

Here your plugin as example.

```php
<?php
use at\fanninger\kirby\extension\webhelper\WebHelper;
require_once 'kirbycms-extension-webhelper-lib.php';

kirbytext::$pre[] = function($kirbytext, $value) {
  $offset = 0;
  $key = 'accordion';
  while ( ($block = WebHelper::getblock($key, $value, $offset)) !== false ) {
    $offset = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS];
    
    $attr = array();
    $attr['class'] = 'accordion-content';
    $content = \Html::tag("div", $block[WebHelper::BLOCK_ARRAY_VALUE_CONTENT], $attr);

    $attr = array();
    $attr['class'] = 'accordion';
    $attr['title'] = $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]['title'];
    $block_new = \Html::tag("section", $content, $attr);

    $start = $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS];
    $length = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS]-$block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS];	
    $value = substr_replace($value, $block_new, $start, $length);
  }
}

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/no-markdown-parsing-with-kirbytags/2070/6 "2025-02-06T17:00:27Z")

</div>

Archived on February 6, 2025, 5:00pm UTC


