Skip to main content

The Lektor Shortcodes plugin allows you to use shortcodes (shortcodes are something like custom tags) in your fields (not templates), so your content doesn't have to have repetitive snippets over and over.

Project description

Lektor Shortcodes
=================

[![PyPI](https://img.shields.io/pypi/v/lektor-shortcodes.svg)](https://pypi-hypernode.com/pypi/lektor-shortcodes)

The Lektor Shortcodes plugin allows you to use shortcodes (shortcodes are
something like custom tags) in your fields (not templates), so your content
doesn't have to have repetitive snippets over and over.

For example, my blog has some specific HTML that I add when I want an image with
a border and caption to be displayed. The HTML looks like this:


~~~html
<div class="alignright">
<a href="image-large.jpg">
<img src="image.jpg" />
<span class="caption">The caption</span>
</a>
</div>
~~~

Copy-pasting this every time gets tedious, and I have to search and replace it
in all the content files every time I want to make a change. With the
shortcodes plugin, this can be written as:

~~~
[% image align=right link="image-large.jpg" image=image.jpg caption="The caption" %]
~~~

Much easier, cleaner and less repetitive.


Installation
------------

To install the plugin, just add `lektor-shortcodes` to your plugins from the
command line:

~~~
lektor plugins add lektor-shortcodes
~~~


Usage
-----

Using the plugin is simple. Just create a config file called `shortcodes.ini` in
your `configs` directory and specify some shortcode templates. The templates are
full Jinja templates, although (due to some limitations of ini files) they need
to be on one line.

For instance, for the example above, the config file could be:

~~~ini
[global]
image = '<div class="align{{ align }}">{% if link %}<a href="{{ link }}"{% if not link.startswith("http") %} data-lightbox="gallery"{% endif %}>{% endif %}<img src="{{ image }}">{% if link %}</a>{% endif %}{% if caption %}<span class="caption">{{ caption }}</span>{% endif %}</div>'
~~~

This will allow you to use shortcodes with optional arguments, like so:

~~~
# An image with no caption or link:
[% image align=right image=hello.jpg %]


# An image with a link:
[% image align=right link=http://www.example.com image=hello.jpg %]

# Link and caption:
[% image align=right link=http://www.example.com image=hello.jpg caption="Hello!" %]
~~~

Shortcodes defined within the section named `global` will be processed
automatically inside any of your site’s Markdown content. It is also possible to
define shortcodes which are only expanded when the Jinja2 template for a page
explicitly requests it. Shortcodes defined in any section not named `global`
will only be applied when the template passed the content through a Jinja2
filter named `shortcode`. For example, if your HTML template references a field
called `body`, you may request expanding shortcodes defined within the
`body-only` section of your config file, like so:

~~~
{{ body|shortcodes(section="body-only") }}
~~~

This will enable all shortcodes from the specified section, in addition to all
globally defined shortcodes. If no section is specified, the filter defaults to
the section named `main`.


Miscellanea
-----------

If you find a bug or have a feature request, please open an issue or file a PR.
Thanks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lektor-shortcodes-0.2.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distributions

lektor_shortcodes-0.2.5-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

lektor_shortcodes-0.2.5-py2-none-any.whl (8.7 kB view details)

Uploaded Python 2

File details

Details for the file lektor-shortcodes-0.2.5.tar.gz.

File metadata

File hashes

Hashes for lektor-shortcodes-0.2.5.tar.gz
Algorithm Hash digest
SHA256 8a11838fc52bac982670c14fe03accab125db9995ddfbcc32963468e4366a72a
MD5 287ded92e06e51036e06270b953d8497
BLAKE2b-256 af33815d2e139abcf5fe75b864f3c7140787b014debf627c5caec87579f5eae7

See more details on using hashes here.

File details

Details for the file lektor_shortcodes-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for lektor_shortcodes-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d95a99fec82b36bfa1633f4b94bec3fd6c0936c77a96a7c37ef9607ae8985a4e
MD5 3475e235a2ceebaf1adef7d6ac784604
BLAKE2b-256 577a752188f82a7511d7dbc15f88959cfc0a99fd30cf28edc5c658302bf24cc1

See more details on using hashes here.

File details

Details for the file lektor_shortcodes-0.2.5-py2-none-any.whl.

File metadata

File hashes

Hashes for lektor_shortcodes-0.2.5-py2-none-any.whl
Algorithm Hash digest
SHA256 81069e1ff0800f1d1a1d7f7841c59256e02ef05b87f28060295b157311531e57
MD5 55be4cf349132860cfb834f9e43ee8fa
BLAKE2b-256 ef720516ffb47771520af81dfdb8a54815ab988ba08693b3205d22459289fd05

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page