Simple shortcodes for Python.
Project description
shrtcodes
pip install shrtcodes
Simple shortcodes for Python.
Example
Text containing shortcodes.
img
- a shortcode.details
- a paired shortcode.
Foo bar baz.
{% img "https://images.com/cutedog.jpg", "A cute dog!" %}
{% details "Some extra info" %}
This is some extra info.
{% end_details %}
Foo bar baz.
Build your shortcodes:
# shortcodes.py
from shrtcodes.shrtcodes import Shrtcodes
shortcodes = Shrtcodes()
# `img_handler` is a shortcode handler.
# * Arguments correspond to the shortcode parameters.
@shortcodes.register('img')
def img_handler(src, alt):
return f'<img src="{src}" alt="{alt}"/>'
# `details_handler` is a paired shortcode handler.
# * Starting arguments correspond to the shortcode parameters.
# * Last argument is the contained block.
@shortcodes.register_paired('details')
def details_handler(summary, block):
return f'<details><summary>{summary}</summary>{block}</details>'
Use your shortcodes:
from shortcodes import shortcodes
text = shortcodes.process('...')
Output:
Foo bar baz.
<img src="https://images.com/cutedog.jpg" alt="A cute dog!"/>
<details><summary>Some extra info</summary>This is some extra info.</details>
Foo bar baz.
Further examples
See the tests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
shrtcodes-0.5.2.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for shrtcodes-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35d10020f353d189a0a4d1c9ed1ff5efe19f4db161e1a5bfccb5691a31e0b85e |
|
MD5 | 2e6e3cf147dc09e2978b7408d7cd0f2f |
|
BLAKE2b-256 | b37a2294ebfa5110388f3be074a9344ac4ebd75a4687a35db652dd5b31568d23 |