Skip to main content

Wagtail anchors set

Project description

Wagtail set

PyPI PyPI - Python Version PyPI - License Lines of code PyPI - Downloads GitHub contributors

Wagtail anchors set.

Installation

Install using pip:

pip install wagtailset

Table of Contents

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 with possibility to changes heading ids. Inspired by wagtail_draftail_anchors with some improvements like possibility to edit previous anchor id and headings' ids.

Instalation

Add 'wagtailset.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. Note: 'anchor-identifier' must be added before any heading('h1',...,'h6') feature and also before 'link' feature:

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

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>

Configuration

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 = "wagtailset.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 wagtailset.draftail_anchors.rich_text for examples.

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

wagtailset-1.1.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

wagtailset-1.1.2-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file wagtailset-1.1.2.tar.gz.

File metadata

  • Download URL: wagtailset-1.1.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for wagtailset-1.1.2.tar.gz
Algorithm Hash digest
SHA256 b4b2964a45abb841d222dc5577631bc54114f844ccdc9529d741cf52ee0be4d5
MD5 c0062ae5b82c7550ddc92437c9fcae52
BLAKE2b-256 52d6f85ac3c137298d824fdaf38fe7072f7d69c461f5ee56c866a45bf2685277

See more details on using hashes here.

File details

Details for the file wagtailset-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: wagtailset-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for wagtailset-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2e19d7d2c71002385018d3890f400423a6c246b9fdb550d2cc2c2070ca8388fb
MD5 bf18fdb6a49f030d17b2d0e5d6779097
BLAKE2b-256 26b54a953fbbaa9b937ecbe34fd902d2344e8a53464020efb967110cceb0b964

See more details on using hashes here.

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