Skip to main content

Simple shortcodes for Python.

Project description

shrtcodes

example workflow name

pip install shrtcodes

Simple shortcodes for Python.

Example:

A toy example:

# example.txt
Hello!

{% img http://cutedogs.com/dog123.jpg "A very cute dog" %}

Foo bar baz...

{% repeat 3 %}
Woop
{% / %}

Bye!
from shrtcodes import Shrtcodes


shortcodes = Shrtcodes()


@shortcodes.register_inline("img")
def handle_img(src, alt):
    return f'<img src="{src}" alt="{alt}"/>'


@shortcodes.register_block("repeat")
def handle_repeat(block, n):
    return block * int(n)


with open("example.txt") as f:
    print(shortcodes.process_text(f.read()))

Output:

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

Uploaded Source

Built Distribution

shrtcodes-1.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shrtcodes-1.0.1.tar.gz
  • Upload date:
  • Size: 3.2 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.1.tar.gz
Algorithm Hash digest
SHA256 d2c1762d9315df182f2e502d3bea14372bc732cf1d6f1897b8f45f95bab8b9e2
MD5 6e4faf35dac091e3c9c290aba7599bb7
BLAKE2b-256 a9fb48e2c570c5e4098a032f61a677da23b1599e3e5a13284c649fcfe98bc38d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shrtcodes-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 364e2e287ff807c84e33527472ee16558e72fea2b1706c47e776b56d4d366b96
MD5 be3c414c8b473c902f4eef2bdc2f1012
BLAKE2b-256 8e3c9dd6ca561b149805333f02eb6db80dc02246b7aa5db41556efe2cf6baee4

See more details on using hashes here.

Supported by

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