Simple shortcodes for Python.
Project description
shrtcodes
pip install shrtcodes
Simple shortcodes for Python.
Example:
A toy example:
# example.txt
Hello!
{% img http://cutedogs.com/dog123.jpg "A very cute dog" %}
Foo bar baz...
{% repeat 3 %}
Woop
{% / %}
Bye!
from shrtcodes import Shrtcodes
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)
with open("example.txt") as f:
print(shortcodes.process_text(f.read()))
Output:
Hello!
<img src="http://cutedogs.com/dog123.jpg" alt="A very cute dog"/>
Foo bar baz...
Woop
Woop
Woop
Bye!
A more useful example would be the generation of this README itself.
See /create_readme.py
and /README.template.md
.
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.1.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for shrtcodes-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 364e2e287ff807c84e33527472ee16558e72fea2b1706c47e776b56d4d366b96 |
|
MD5 | be3c414c8b473c902f4eef2bdc2f1012 |
|
BLAKE2b-256 | 8e3c9dd6ca561b149805333f02eb6db80dc02246b7aa5db41556efe2cf6baee4 |