Link for Liquid Tags

Liquid Tags

PelicanCMS supports plugins. Liquid Tags is one of them. This plugin is what can be considered as actions for a wiki like WikkaWiki.

Link is a tag that enables to define the rendering style of an hyperlink according to a type - a CSS class, in fact - given as a parameter.

Link example:

{% link {static}../code/ "Source code" "download" "Download the source file" %}

Source code

Link Tag
This implements a Liquid-style link tag for Pelican,
based on the Liquid_tags / b64img tag

{%link [http[s]:/]/path/to/file text | ["text" ["icon-type"] ["title"]] %}

{% link https://path/to/filename %}
{% link https://path/to/filename "Click" %}
{% link https://path/to/filename "Click" "download" %}
{% link https://path/to/filename "Click" "download" "This is a download link" %}

Add CSS rules:

[class^="icon-"]:before, [class*=" icon-"]:before {
    font-weight: normal;
    font-style: normal;
    margin-left: .5em;
.icon-download:before {
.icon-link:before {
.icon-mail:before {

    <a class="button" href="https://path/to/filename" rel="external norefferer noopener" target="_blank" title="Link">
        <div class="inset-text">Click<i class="icon-download"></i></div>
import re
from .mdx_liquid_tags import LiquidTags

SYNTAX = '{% link [http[s]:/]/path/to/file text | ["text" ["icon-type"] ["title"]] %}'

# Regular expression to match the entire syntax
ReLnk = re.compile(ur"""(?P<class>\S.*\s+)?(?P<src>(?:https?:\/\/|\/|\S+\/)\S+)(?P<text>\s+.+)?""", re.UNICODE)

# Regular expression to split the title text and icon type
ReTextType = re.compile(ur"""(?:")(?P<text>[^"]+)?(?:")\s+(?:")(?P<type>[^"]+)?(?:")\s*(?:")?(?P<title>[^"]+)?(?:")?""", re.UNICODE)

def link(preprocessor, tag, markup):
    attrs = None
    rel = 'external '

    match =

    if match:
        attrs = dict([(key, val.strip()) for (key, val) in match.groupdict().items() if val])
        raise ValueError('Error processing input. '
                         'Expected syntax: {0}'.format(SYNTAX))

    if 'text' in attrs:
        match =['text'])
        if match:
        if not attrs.get('type'):
            attrs['type'] = None
        if not attrs.get('title'):
           attrs['title'] = None

    text = attrs['text'] or 'LINK'
    link_url = attrs['src'] or 'none'
    type = attrs['type'] or 'link'
    title = attrs['title'] or 'Link'

    if 'mail' == type:
        rel = ''

    if link_url:
        link_out = u"""
                <a class="button" href="{link_url}" rel="{rel}noreferrer noopener" target="_blank" title="{title:s}">
                    <span class="inset-text">{text}<i class="icon-{type}"></i></span>
        """.format(link_url=link_url, rel=rel, title=title, text=text, type=type).strip()
        raise ValueError("Error processing input, expected syntax: {0} {1} {2} {3} {4}".format(SYNTAX, link_url, text, type, title))

    return link_out

# ---------------------------------------------------
# This import allows image tag to be a Pelican plugin 
from liquid_tags import register  # noqa