Skip to main content

Simple shortcodes for Python.

Project description

shrtcodes

example workflow name

pip install shrtcodes

Simple shortcodes for Python.

Example:

from shrtcodes import Shrtcodes

in_text = """
Hello!

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

Foo bar baz...

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

Bye!
""".strip()

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)


out_text = shortcodes.process_text(in_text)
print(out_text)

Output:

Hello!

<img src="http://cutedogs.com/dog123.jpg" alt="A very cute dog"/>

Foo bar baz...

Woop
Woop
Woop

Bye!

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.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

shrtcodes-1.0.0-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

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