Skip to main content

Wagtail Draftail Anchors

Adds the ability to add and edit anchors in the Draftail rich text editor, as well as automatically adding (slug-form) anchor ids to all headings.

Installation

Install using pip:

pip install wagtail-draftail-anchors

Add 'wagtail_draftail_anchors' to INSTALLED_APPS below wagtail.admin.

Add 'anchor-identifier' to the features of any rich text field where you have overridden the default feature list. The feature must be added before any heading('h1',...,'h6') feature:

body = RichTextField(features=['anchor-identifier', 'h2', 'h3', 'bold', 'italic', 'link'])

Configuration

Rendered representation of anchors

By default, anchor-identifier rich text entities will be rendered as HTML anchor elements, e.g.:

<a href="#my-element" id="my-element" data-id="my-element">My element</a>

This package provides an alternative renderer that renders anchor-identifier entities as HTML span elements, e.g.:

<span id="my-element">My element</span>

The desired renderer can be specified using the DRAFTAIL_ANCHORS_RENDERER setting. To use the span renderer, configure your application as follows:

DRAFTAIL_ANCHORS_RENDERER = "wagtail_draftail_anchors.rich_text.render_span"

It is possible to define your own renderer. It should be a callable that takes a dict of attributes, and returns a string containing the opening tag of the HTML element that represents the anchor target. The dict passed to the renderer, for an anchor with an identifier of "my-anchor", would look like the following:

{"data-id": "my-anchor", "href": "#my-anchor", "id": "my-anchor", "linktype": "my-anchor"}

If you define your own renderer, you should set the value of DRAFTAIL_ANCHORS_RENDERER to your custom renderer's import path.

See render_span and render_a in wagtail_draftail_anchors.rich_text for examples.

Release files for wagtail-draftail-anchors 0.7.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 wagtail-draftail-anchors 0.7.0
File Size Uploaded
wagtail_draftail_anchors-0.7.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-draftail-anchors 0.7.0
File Interpreter ABI Platform
wagtail_draftail_anchors-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size:23.9 kB

Release files / wagtail_draftail_anchors-0.7.0.tar.gz

Download URL wagtail_draftail_anchors-0.7.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8e2975595fb476e1b1f78ec4ff0e810fac3751956dd94b97d20b2f435536f757
BLAKE2b-256 checksum
How to use checksums
8e33d036de1bb2c9b8139973f6955abec573c65b0e84157a216f23c00b8b6f56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / wagtail_draftail_anchors-0.7.0-py3-none-any.whl

Download URL wagtail_draftail_anchors-0.7.0-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
302b2b50236efed43f9d84d2a0483a9fcf31c98586ef364eb348c061877c249a
BLAKE2b-256 checksum
How to use checksums
95fd18bcc76cf829d7c28a69acf6e7820d39bf098095bb0ebe31cd1616e31363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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