Simple shortcodes for Python.
Project description
shrtcodes
pip install shrtcodes
Simple shortcodes for Python.
Example:
from shrtcodes import Shrtcodes
in_text = """
Hello!
{% img http://cutedogs.com/dog123.jpg "A very cute dog" %}
Foo bar baz...
{% repeat 3 %}
Woop
{% / %}
Bye!
""".strip()
shortcodes = Shrtcodes()
@shortcodes.register_inline("img")
def handle_img(src, alt):
return f'<img src="{src}" alt="{alt}"/>'
@shortcodes.register_block("repeat")
def handle_repeat(block, n):
return block * int(n)
out_text = shortcodes.process_text(in_text)
print(out_text)
Output:
Hello!
<img src="http://cutedogs.com/dog123.jpg" alt="A very cute dog"/>
Foo bar baz...
Woop
Woop
Woop
Bye!
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-1.0.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for shrtcodes-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8029e48af4211693863c52ba1714297461ac84f031bfbf86df95ec76f658dd1d |
|
MD5 | 7b664a51d6d95fe61033ecd4661295c0 |
|
BLAKE2b-256 | 684585983e13fd699c4f853ad0e08f55f92a3929d8d969c10dfe27ab6fc1906b |