Skip to main content

Text shortcodes resolver

Installation

pip install wc-shortcodes

Usage

Simple usage:

from wc_shortcodes.registry import CodesRegistry
from wc_shortcodes.transformer import transform


registry = CodesRegistry()


# Adding handler for a specific shortcode:
@registry.register()
def shortcode(entity, context={}):
  return entity.content


# Transforming some content using registered resolvers.
transform(registry, '''
[shortcode unhandled-parameter="it's value"]
Content.
[/shortcode]
''')
# Result will be:
# > 'Content.'

Shortcode handler can also be defined with additional parameters:

@registry.register(
  # Shortcode custom name:
  'name',
  # Does this shortcode can handle multiple entities at a time.
  # `False` by default.
  multiple=False,
  # Should entity's `content` property be parsed and resolved before it
  # passed to this handler.
  # Or you should do something with raw content instead.
  # `True` by default.
  autoresolve_content=True,
)

Multiresolver

Multiresolver is not the same as singular one(duh..).

This configuration was made for performance reasons.

For example if there is, lets say, 10 same shortcuts with different parameters passed inside one text. It's obvious that whose 10 items will do same work for 10 times. So to prevent such unefficiency multihandlers had been added.

@registry.register(multiple=True)
def shortcode(
  # They receive all current entities as `*args`.
  entities: List[Entity],
  context={}
) -> List[str]:
  return [
    # And must return result in the exact same order as they have been passed.
    entity.content for entity in entities
  ]

Django

Installation

In settings.py:

INSTALLED_APPS += [
  'wc_shortcodes.contrib.django',
]

Usage

Specific implementation not yet ready. Can be used as described before.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[0.1.0]

Initial version.

Metadata

Release files for wc-shortcodes 0.1.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 wc-shortcodes 0.1.0
File Size Uploaded Provenance Actions
wc-shortcodes-0.1.0.tar.gz 9.7 kB Without provenance Details for wc-shortcodes-0.1.0.tar.gz

Release files / wc-shortcodes-0.1.0.tar.gz

Download URL wc-shortcodes-0.1.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e17fd8eeb1fad8e878678b38a6ec3a4af4aba9caa7a004d729bdce8137b06277
BLAKE2b-256 checksum
How to use checksums
5f4e4a1c78725ac3425e314a9570164457df7754f2622f9fd4b3ebfe6a928c0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Security for wc-shortcodes 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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