Simple shortcodes for Python.
Project description
shrtcodes
Simple shortcodes for Python.
pip install shrtcodes
Example
Text containing shortcodes.
img
- a "single line shortcode".details
- a "block" 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 single line shortcode handler.
# * Arguments correspond to the shortcode parameters (pipe separated).
def img_handler(src, alt):
return f'<img src="{src}" alt="{alt}"/>'
# `details_handler` is a block shortcode handler.
# * First argument is the block.
# * Subsequent arguments correspond to the shortcode parameters (pipe separated).
def details_handler(details, summary):
return f'<details><summary>{summary}</summary>{details}</details>'
# Call `make_process` with:
# * A dict of single line shortcode handlers.
# * A dict of block 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.1.0.tar.gz
(2.1 kB
view hashes)
Built Distribution
Close
Hashes for shrtcodes-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d2342ca5bbc258b026b4bc3f231338aafb14cf82a7f1251e7c7d83add3704ee |
|
MD5 | ee9c45859962eea1bb131fb3908a6140 |
|
BLAKE2b-256 | 3c8a478f9e80d6ed3725f49a00bd4b3411a7c9076c0a78aeb8620a05cd886589 |