https://github.com/peter554/shrtcodes
Shortcodes for Python
https://github.com/peter554/shrtcodes
python shortcodes
Last synced: over 1 year ago
JSON representation
Shortcodes for Python
- Host: GitHub
- URL: https://github.com/peter554/shrtcodes
- Owner: Peter554
- License: mit
- Created: 2020-07-03T21:00:12.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T06:51:59.000Z (almost 3 years ago)
- Last Synced: 2025-03-17T09:44:33.389Z (over 1 year ago)
- Topics: python, shortcodes
- Language: Python
- Homepage: https://pypi.org/project/shrtcodes/
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shrtcodes

`pip install shrtcodes`
Shortcodes for Python.
## Example:
A toy example.
Define our shortcodes:
```py
# example.py
from shrtcodes import Shrtcodes
shortcodes = Shrtcodes()
# {% img src alt %} will create an image.
@shortcodes.register_inline("img")
def handle_img(src: str, alt: str) -> str:
return f'
'
# {% repeat n %}...{% / %} will repeat a block n times.
@shortcodes.register_block("repeat")
def handle_repeat(block: str, n: str) -> str:
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!

Foo bar baz...
Woop
Woop
Woop
Bye!
```
A more useful example would be the generation of this README itself.
See [`make_readme.py`](/make_readme.py) and [`.README.template.md`](/.README.template.md).