Adding markdown link attribute problem with styling in textfield

Hello,
I have added a attribute (data-link) to the kirby link-tag in the file kirby > extensions > tags.php.

   // link tag
  kirbytext::$tags['link'] = array(
  'attr' => array(
    'text',
    'class',
    'role',
    'title',
    'rel',
    'lang',
    'target',
    'popup',
    'data-link'
  ),
  'html' => function($tag) {
  
    $link = url($tag->attr('link'), $tag->attr('lang'));
    $text = $tag->attr('text');

    if(empty($text)) {
      $text = $link;
    }

    if(str::isURL($text)) {
      $text = url::short($text);
    }

    return html::a($link, $text, array(
      'rel'       => $tag->attr('rel'),
      'class'     => $tag->attr('class'),
      'role'      => $tag->attr('role'),
      'title'     => $tag->attr('title'),
      'data-link' => $tag->attr('data-link'),
      'target'    => $tag->target()
    ));
    }
 );

But if I write this attribute in a markdown textfield it will not getting grey like the other attributes.
What have I to do that it will recognize as a attribute in the markdownfield?

14

Cheers

You will have to modify the pattern that is used to identify an attribute in the markdown editor.

Probably the pattern in the following lines:
https://github.com/JonasDoebertin/kirby-visual-markdown/blob/785fb4f37b98ebabb2e95ea717b47ca3e814c0fb/assets/js/kirbytags-mode.js#L35

Currently, it only gets patterns with alphanumeric characters.

Hello Sonja,
actually I havn’t thought about that it is a result from visualmarkdown.
Thanks that you have realized that I use that :).

So I have added the dash to the regex. Here it works.
https://regex101.com/r/bqfdCT/3
but not in the visual markdown. What do I’m wrong?

Looks like you have to add the dash to the pattern on line 53 as well.

1 Like

You are right. I thought this is only for the value.

Thank you very much!