Kirbytag link & HTML markup wrapped into "text"

Hi,

I’m trying to render a Kirby link with HTML (abbr markup) inside the “text” part, as follow:
(link: https://... text: <abbr>test</abbr>)

For now, the abbr is rendered as plain text and not as HTML.

Any idea how to achieve this?
Thanks!

I’m not sure if there is a shorter way, but you can create your own tag or extend the link tag.

Thanks, but unfortunately my skills are too bad to achieve this…

Without using a custom Kirby tag, you can activate Markdown Extra in your config file and use its syntax for abbreviations:

*[HTML]: Hyper Text Markup Language

So you can write your link in a simple way, as long as you define the abbreviation somewhere after:

(link: http://html.com text: HTML)

*[HTML]: Hyper Text Markup Language

Dear all,
I’m still stuck into this issue :confused:

If anyone could provide an example of an extended KirbyTag for links to include <span class="xx"> and <abbr> markups into “text” links, would be awesome.

Thanks!

Again, maybe there is no need for a KirbyTag. Add this line to config.php:

'markdown' => [ 'extra' => true ]

Then:

(link: http://example.com text: HTML class: xxx)

*[HTML]: Hyper Text Markup Language

Will give you:

<a href="http://example.com" class="xxx"><abbr title="Hyper Text Markup Language">HTML</abbr></a>

Thanks Cadars, it works with your code for <abbr>. How about <span> markups for some words included into “text”?

Question: do you always want these spans or conditionally?

Overwriting a kirbytag is nothing but making a copy of the source code of the original in a plugin, then make the desired changes.

Why do you means by always? I want to be able to use <span>s in all areas of my website. I don’t know if I can easily change classes of <span>, through. Why Kirby skip HTML tags by default?

You can absolutely use HTML in markdown, that’s not the issue. But I thought you wanted it especially inside link tags.

Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated <span style="color:red">they live in Bookmarksgrove</span> right at the coast of the Semantics,

Bildschirmfoto von 2020-11-26 21-24-34

I’m a bit confused now…

1 Like

Indeed, I need to use <span> into Kirby links tags

What I meant above was if you always want to have spans in link tags or only in some link tags. Because if only sometimes, then your link tag needs some condition when to apply a span and when not to.

But play around with making a copy of the tag and then change what you want.

Thanks @pixelijn, I understand what you mean. I need <span> always, it’s not conditional but only for layout goals (styling fragments of the link). As I said before, I don’t understand how to extend the kirbytag. Is there a recipe/tutoriel for this?

@ahmetbora posted the link to how to set up a plugin for Kirbytags above:

Here you can find the original Kirbytag:

So that means, in a plugin folder, let’s say mytags, you create an index.php with the following content:

<?php

Kirby::plugin('your/plugin', [
    'tags' => [
        'link' => [
           'attr' => [
            'class',
            'lang',
            'rel',
            'role',
            'target',
            'title',
            'text',
        ],
        'html' => function ($tag) {
            if (empty($tag->lang) === false) {
                $tag->value = Url::to($tag->value, $tag->lang);
            }

            return Html::a($tag->value, $tag->text, [
                'rel'    => $tag->rel,
                'class'  => $tag->class,
                'role'   => $tag->role,
                'title'  => $tag->title,
                'target' => $tag->target,
            ]);
        }
        ]
    ]
]); 

Now you should be able to change what you need to change.