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.
{% enddetails %}
Foo bar baz.
Build a process
function:
# shortcodes.py
from shrtcodes.shrtcodes import make_process
# `img_handler` is a shortcode handler.
# * Arguments correspond to the shortcode parameters.
def img_handler(src, alt):
return f'<img src="{src}" alt="{alt}"/>'
# `details_handler` is a paired shortcode handler.
# * First argument is the contained block.
# * Subsequent arguments correspond to the shortcode parameters.
def details_handler(details, summary):
return f'<details><summary>{summary}</summary>{details}</details>'
# Call `make_process` with:
# * A dict of shortcode handlers.
# * A dict of paired shortcode handlers.
process = make_process({
'img': img_handler
}, {
'details': details_handler
})
Use your process
function:
from shortcodes import process
text = 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.2.0.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for shrtcodes-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c3455fd82b58b647261d53c0541b88b1f43d1e14c2aca178e5d5279f553c5d7 |
|
MD5 | e3fc0262865952a1a2b90c202ee3207c |
|
BLAKE2b-256 | 22b7f4bc5400458d0a3ffd3995fd4de4d81f5a401ea2a0cb88b36b83b62471a8 |