Skip to main content

Simple shortcodes for Python.

Project description

shrtcodes

Build Status

pip install shrtcodes

Simple shortcodes for Python.

Example

Text containing shortcodes.

  • img - a shortcode.
  • details - a paired shortcode.
Foo bar baz.

{% img "https://images.com/cutedog.jpg", "A cute dog!" %}

{% details "Some extra info" %}
This is some extra info.
{% end_details %}

Foo bar baz.

Build your shortcodes:

# shortcodes.py

from shrtcodes.shrtcodes import Shrtcodes

shortcodes = Shrtcodes()

# `img_handler` is a shortcode handler. 
#   * Arguments correspond to the shortcode parameters.  
@shortcodes.register('img')
def img_handler(src, alt):
    return f'<img src="{src}" alt="{alt}"/>'

# `details_handler` is a paired shortcode handler.
#   * Starting arguments correspond to the shortcode parameters.  
#   * Last argument is the contained block.
@shortcodes.register_paired('details')
def details_handler(summary, block):
    return f'<details><summary>{summary}</summary>{block}</details>'

Use your shortcodes:

from shortcodes import shortcodes
text = shortcodes.process('...')

Output:

Foo bar baz.

<img src="https://images.com/cutedog.jpg" alt="A cute dog!"/>

<details><summary>Some extra info</summary>This is some extra info.</details>

Foo bar baz.

Further examples

See the tests.

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

Uploaded Source

Built Distribution

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

shrtcodes-0.5.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shrtcodes-0.5.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/2.7.15 Darwin/17.7.0

File hashes

Hashes for shrtcodes-0.5.3.tar.gz
Algorithm Hash digest
SHA256 a470b9a347f8d9762b4bf01b15340547f1ea4571195e790404aea9010e036660
MD5 662b88ea94966df1ef613db9632eb6e2
BLAKE2b-256 70360158a8e59b652c5238262ab7ba452b997a01ba867779cf6d7f82be015876

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shrtcodes-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/2.7.15 Darwin/17.7.0

File hashes

Hashes for shrtcodes-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3830300e04a8cbdfece8eaf5fa03424df230e54ef330cb0311be8a857976f17d
MD5 827ca303e767b7fa2837637adc6c0591
BLAKE2b-256 a333a60b0aee0e1c99444facf1e8ddd6b027ceb31bc5cbd6ee9fa28dd3e97f84

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