Skip to main content

shrtcodes

example workflow name

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: str, alt: str) -> str:
    return f'<img src="{src}" alt="{alt}"/>'


# {% 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!

<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 make_readme.py and .README.template.md.

Metadata

Release files for shrtcodes 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shrtcodes 1.2.0
File Size Uploaded
shrtcodes-1.2.0.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shrtcodes 1.2.0
File Interpreter ABI Platform
shrtcodes-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / shrtcodes-1.2.0.tar.gz

Download URL shrtcodes-1.2.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3a7fbf4f4be4ca20dd7165d597b1bec2c4c47d1f555034add29d1e7cbe55f538
BLAKE2b-256 checksum
How to use checksums
36ae709a568d82268e67815dee3462b3571172db69fad24fef8bbe69287c430b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.6 Darwin/22.6.0

Release files / shrtcodes-1.2.0-py3-none-any.whl

Download URL shrtcodes-1.2.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
941f665cfb1adc16ea8d4e1236c131329df072f3d63652113d3d9145f67c74d5
BLAKE2b-256 checksum
How to use checksums
f43d7fefd4cf56615e13782762d0f5c942fd2d9ebd02b25d7c84d3bf058164c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.6 Darwin/22.6.0

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page