Simple shortcodes for Python.
Project description
shrtcodes
pip install shrtcodes
Shortcodes for Python.
Example:
A toy example.
Define our shortcodes:
# example.py
from shrtcodes import Shrtcodes
shortcodes = Shrtcodes()
# {% img src alt %} will create an image.
@shortcodes.register_inline("img")
def handle_img(src, alt):
return f'<img src="{src}" alt="{alt}"/>'
# {% repeat n %}...{% / %} will repeat a block n times.
@shortcodes.register_block("repeat")
def handle_repeat(block, n):
return block * int(n)
# we can call process_text to get the final text.
in_text = "..."
out_text = shortcodes.process_text(in_text)
# or, we can create a CLI.
shortcodes.create_cli()
python example.py --help
usage: example.py [-h] [--check_file CHECK_FILE] in_file
positional arguments:
in_file File to be processed
options:
-h, --help show this help message and exit
--check_file CHECK_FILE
Checks the output against this file and errors if
there is a diff
Write some text:
# example.txt
Hello!
{% img http://cutedogs.com/dog123.jpg "A very cute dog" %}
Foo bar baz...
{% repeat 3 %}
Woop
{% / %}
Bye!
Process the text:
python example.py example.txt
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.4.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for shrtcodes-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2af2cad7b56bf32f00f4337ac5b70faabb6b116ab0a6a20b8ab6ea2b82087ba |
|
MD5 | 5f740ef82ec838585b6c521f24271231 |
|
BLAKE2b-256 | f766c759c67994426cf813abbd465102328f3d3212140b809ef150f51ea08979 |