Skip to content

Add an ents_template displaCy option for the entity container - #14077

Open
Motaghi wants to merge 5 commits into
explosion:masterfrom
Motaghi:fix/12267
Open

Motaghi wants to merge 5 commits into
explosion:masterfrom
Motaghi:fix/12267

Conversation

@Motaghi

@Motaghi Motaghi commented Nov 13, 2026

Copy link
Copy Markdown

Description

The template option replaces the markup for each entity, but EntityRenderer.render_ents always wraps the result in TPL_ENTS, so the outer <div class="entities"> cannot be changed. EntityRenderer now reads an optional ents_template and falls back to TPL_ENTS when it is unset. It is a format string with the same {content} and {dir} fields as TPL_ENTS. The name pairs with TPL_ENTS and follows kb_url_template; happy to rename it. Related to #12267: this covers only the entity visualizer. The span renderer's TPL_SPANS container is unchanged, so I have left the issue's closure to the maintainer.

Without the option the output is unchanged. The new issue-marked test in spacy/tests/test_displacy.py renders manual data with a custom container in both text directions and checks that the text is still escaped; it fails on master and passes with the change. The option gets one row in the entity visualizer table in top-level.mdx, including a note to double literal braces. All 28 tests in test_displacy.py pass on macOS, Python 3.11, using a 3.8.17 wheel with the patched render.py copied in, since there was no local Cython build; that wheel's original render.py is identical to master's. Changed-file mypy, Ruff formatting and import ordering pass.

I used Codex (gpt-6.1-sol) to help write the patch and tests and to run the checks above, and Claude Opus 5.5 reviewed the change independently. I've read and verified the diff myself.

Types of change

New option for the entity visualizer, with a docs entry.

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant