Skip to main content

Simple shortcodes for Python.

Project description

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, 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 make a general 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


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.3.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shrtcodes-1.0.3-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file shrtcodes-1.0.3.tar.gz.

File metadata

  • Download URL: shrtcodes-1.0.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.15.0-53-generic

File hashes

Hashes for shrtcodes-1.0.3.tar.gz
Algorithm Hash digest
SHA256 a7250165d47d0fbcd6a17016368b1cd7486f2de048357d07df97c504725cb0b3
MD5 c79774af09683a03c911a2b45935001e
BLAKE2b-256 805da43258fd6d66a7de51dd042a17592856d1646e70dca3d28527374b0a7b3f

See more details on using hashes here.

File details

Details for the file shrtcodes-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: shrtcodes-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.15.0-53-generic

File hashes

Hashes for shrtcodes-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 23d413102e17600b86d6dc4171415f6c44ad13ebd2ca0408a968b26b24aeb8f0
MD5 f17018151ff66ebb618d0be67c00f91b
BLAKE2b-256 86deaf2a3706dcb9c13e9d5d399f1fa8d6914e325e1e0d9e12b3fc3b9cd43c9d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page