Wagtail shortcode
Wagtail shortcode adds a custom Draftail enitity to provide a custom linktype ("shortcode"), giving you the ability to assign values in a similar way to normal links as well as decide how they should be rendered on the page.
Installation
python -m pip install wagtail-shortcode- ...
Add 'wagtail_shortcode' to INSTALLED_APPS.
Register a LinkHandler, to control how the new linktype renders on the front-end (|richtext filter).
LinkHandlers must be registered within a wagtail_hooks.py file under an app directory and use an identifier matching SHORTCODE_ANCHOR_TARGET_IDENTIFIER, for example:
# ./utils_app/wwgtail_hooks.py
from django.utils.html import escape
from wagtail import hooks
from wagtail.rich_text import LinkHandler
from wagtail_shortcode.handlers import SHORTCODE_ANCHOR_TARGET_IDENTIFIER
class CustomShortcodeLinkHandler(LinkHandler):
identifier = SHORTCODE_ANCHOR_TARGET_IDENTIFIER
@classmethod
def expand_db_attributes(cls, attrs):
href = attrs["shortcode"]
# Do something clever
return '<a href="%s">' % escape(href)
@hooks.register("register_rich_text_features")
def register_shortcode_link(features):
features.register_link_type(CustomShortcodeLinkHandler)
Add shortcode to the features argument of any rich text field where you have overridden the default feature list:
class Header(models.Model):
content = RichTextField(
features=["shortcode", "h2", "h3", "bold", "italic", "link"]
)
Configuration
Updating the window prompt's help-text
When adding shortcode within the editor, a window prompt will appear, the text within this prompt can be customised by providing a value for SHORTCODE_HELP_TEXT within your project's settings file. This can be helpful as to inform editors of the expected behaviour of your custom LinkHandler.
SHORTCODE_HELP_TEXT="Enter a shortcode value"
The window.prompt function is a JavaScript method which supports basic text formatting using special characters, as such a newline character can be included using \n if needed.
Contributing
Metadata
Release files for wagtail-shortcode 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| wagtail_shortcode-1.0.3.tar.gz | 9.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wagtail_shortcode-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.3 kB
Release files / wagtail_shortcode-1.0.3.tar.gz
| Download URL | wagtail_shortcode-1.0.3.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63f8500ed8ab7c27a54c407fd6d49f7a0e07621c45a0d51e4e6194620e4664c5
|
|
BLAKE2b-256 checksum How to use checksums |
f38c1c40bff39f347bb3f529c1c660340a54cf8416704f8b90155b39462816c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / wagtail_shortcode-1.0.3-py3-none-any.whl
| Download URL | wagtail_shortcode-1.0.3-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16dbab11274a46fcc82de1dff966d37c35678b66d4542ebc2051c8c44208d910
|
|
BLAKE2b-256 checksum How to use checksums |
c8b5407ed8559b632294b5ef7194df61e948f60fd333485a831f91ab9bbac2d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for wagtail-shortcode 1.0.3
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.