Skip to main content

Wagtail Show Hidden Characters

Wagtail Show Hidden Characters adds Draftail toolbar controls for displaying invisible characters and structural markers in Wagtail rich text fields.

It helps editors identify regular spaces, non-breaking spaces, soft hyphens, line breaks, paragraph boundaries, heading levels, and empty trailing paragraphs.

It provides three independently configurable rich text features:

  • show-hidden-chars, a button that shows or hides hidden characters and structural markers in the editor.
  • insert-non-breaking-space, a button that inserts a non-breaking space.
  • insert-soft-hyphen, a button that inserts a soft hyphen.

Installation

Install the package with pip:

pip install wagtail-show-hidden-characters

Add wagtail_show_hidden_characters to INSTALLED_APPS:

INSTALLED_APPS = [
    "wagtail_show_hidden_characters",
]

Enable the features on a RichTextField:

from wagtail.fields import RichTextField


body = RichTextField(
    features=[
        "h2",
        "h3",
        "bold",
        "italic",
        "link",
        "show-hidden-chars",
        "insert-non-breaking-space",
        "insert-soft-hyphen",
    ],
    blank=True,
)

You can also enable the features through WAGTAILADMIN_RICH_TEXT_EDITORS:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    "default": {
        "WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea",
        "OPTIONS": {
            "features": [
                "h2",
                "h3",
                "bold",
                "italic",
                "link",
                "show-hidden-chars",
                "insert-non-breaking-space",
                "insert-soft-hyphen",
            ],
        },
    },
}

Supported characters and shortcuts

  • Press Control + Option + I on macOS to toggle hidden-character visibility.
  • Press Ctrl + Alt + I on Windows and Linux.

The visibility feature displays the following invisible characters:

Character Unicode Marker macOS input Windows input Linux input
Space U+0020 · Space Space Space
Non-breaking space U+00A0 ° Option + Space Alt + 0160 Ctrl + Shift + U, 00A0, then Enter
Soft hyphen U+00AD ¬ n/a Alt + 0173 Ctrl + Shift + U, 00AD, then Enter
Line break U+000A Shift + Enter Shift + Enter Shift + Enter

Character-entry shortcuts may depend on the operating system, keyboard layout, numeric keypad, and configured input method.

The visibility feature also displays the following structural markers:

Item Marker Input
Paragraph Enter
Heading H1 to H6 # to ######
Document end # n/a

The document-end marker makes empty trailing paragraphs visible. Editors will usually want to remove these paragraphs.

A soft hyphen is also called a syllable hyphen or discretionary hyphen. A line break is also called a soft return.

Behavior

The show/hide state is stored in browser localStorage, so the editor remembers the user's last visibility preference. The state is shared across all Draftail rich text editors on the page.

The insert buttons insert a character at the current Draftail selection. If text is selected, the selected text is replaced. This matches normal text input behavior.

Only non-breaking spaces and soft hyphens have insert buttons. Draftail already provides a line break button. Paragraphs and headings use the standard Draftail controls and keyboard input.

Toolbar button tooltips show the platform shortcut when one is available.

Hidden-character markers are visual only and are rendered as CSS decorations. They do not change the stored rich text or its rendered HTML.

Because the markers are rendered with CSS, Draftail retains its native cursor behavior. Browser spellcheck also continues to treat words containing soft hyphens as single words.

The soft hyphen character itself has zero width, but its visible marker occupies space. As a result, cursor movement around a displayed soft hyphen can feel counterintuitive. This is a known limitation.

Development and testing

Install the package with its test dependencies:

make install

Activate the virtual environment:

source .venv/bin/activate

Run all checks and tests:

make test

Fix code style:

make fix-codestyle

Demo project

Use the tests/test_project Django/Wagtail project for manual testing and demonstrations:

python tests/test_project/manage.py migrate
python tests/test_project/manage.py createsuperuser
python tests/test_project/manage.py create_content
python tests/test_project/manage.py runserver

The homepage illustrates the supported markers and rich text features.

Release

Releases are published to PyPI by GitHub Actions when a v* tag is pushed.

Update the project version in pyproject.toml:

git add pyproject.toml
git commit -m "Release 0.1.1"
git tag v0.1.1
git push
git push origin v0.1.1

The Git tag must match the package version with a v prefix. For example, version = "0.1.1" uses the tag v0.1.1.

You can create a GitHub Release in the web interface after pushing the tag. If you create the tag through the GitHub Release interface, make sure the version bump commit is already present on the target branch.

To build and inspect the package locally:

uv build

This writes the release artifacts to dist/. Before publishing, inspect the generated files and verify that the package data is included:

tar -tf dist/wagtail_show_hidden_characters-*.tar.gz
unzip -l dist/wagtail_show_hidden_characters-*.whl

Release files for wagtail-show-hidden-characters 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 wagtail-show-hidden-characters 0.1.0
File Size Uploaded
wagtail_show_hidden_characters-0.1.0.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-show-hidden-characters 0.1.0
File Interpreter ABI Platform
wagtail_show_hidden_characters-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / wagtail_show_hidden_characters-0.1.0.tar.gz

Download URL wagtail_show_hidden_characters-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e6dddfeaff28c57a1fa776545aa11ab07e4e09a8d933a4b9fc10c39df277b63b
BLAKE2b-256 checksum
How to use checksums
0e153f8a181b590a858c06a5cebc1093ac48f62f4c0e9a52ea049334fa3dc0c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wagtail_show_hidden_characters-0.1.0-py3-none-any.whl

Download URL wagtail_show_hidden_characters-0.1.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecfaa6ecffc302e014c6c1167410e54c64c7b2ea461bc3b08aaafaa3b8dbbad9
BLAKE2b-256 checksum
How to use checksums
975de4185eb29f530b056edd92e3d07ed1ccbdae94559eb6595d695bc7ce0290
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.0 This release

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