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.
{% end_details %}
Foo bar baz.
Build your shortcodes:
# shortcodes.py
from shrtcodes.shrtcodes import Shrtcodes
shortcodes = Shrtcodes()
# `img_handler` is a shortcode handler.
# * Arguments correspond to the shortcode parameters.
@shortcodes.register('img')
def img_handler(src, alt):
return f'<img src="{src}" alt="{alt}"/>'
# `details_handler` is a paired shortcode handler.
# * Starting arguments correspond to the shortcode parameters.
# * Last argument is the contained block.
@shortcodes.register_paired('details')
def details_handler(summary, block):
return f'<details><summary>{summary}</summary>{block}</details>'
Use your shortcodes:
from shortcodes import shortcodes
text = shortcodes.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.5.0.tar.gz
(3.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shrtcodes-0.5.0.tar.gz.
File metadata
- Download URL: shrtcodes-0.5.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/2.7.15 Darwin/17.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a672d1e02206c8b4f7f03f709a61d4d375e69f75ad37affe6208ddd32a28638d
|
|
| MD5 |
8c2ce0c336fb6fe3ec70b40205d84950
|
|
| BLAKE2b-256 |
f0f800b35b664b3f727ebbac1950c9faa9442c24797a73dce44cf3c60fce3db0
|
File details
Details for the file shrtcodes-0.5.0-py3-none-any.whl.
File metadata
- Download URL: shrtcodes-0.5.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/2.7.15 Darwin/17.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7847170b558412724dfde7b25074552870edfc801d6e2a5de8f6fff46597330
|
|
| MD5 |
92dfe1c499ac5519a9502cf15f072753
|
|
| BLAKE2b-256 |
eaa0e30c53c465c384587f42138920ab9e5ea4fe9239614f428f8ab4cdc620c7
|