Skip to content

Update AutoNumbering transform. - #14400

Open
gmilde wants to merge 12 commits into
sphinx-doc:masterfrom
gmilde:ids
Open

gmilde wants to merge 12 commits into
sphinx-doc:masterfrom
gmilde:ids

Conversation

@gmilde

@gmilde gmilde commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

a) Ensure that enumerable elements (tables, figures and literal_blocks)
have an ID. (In Docutils > 0.22, nodes.document.note_implicit_target()
does not genereate an ID if legacy_ids_ is False.)

b) Title-derived IDs for enumerable elements:

"Enumerable elements" get an auto-ID in the AutoNumbering SphinxTransform
and a self-link (¶) after the caption/title in the HTML document.

Currently, the ID is made of the "auto-id-prefix" + a running number
(id1, id2, ...). The generated IDs are not stable -- inserting/removing
an enuerable element, footnote, or section with non-Latin heading will
change the running number!

Base the generated IDs on the caption or title text instead (similar to
sections). To avoid changed IDs when documents are re-compiled, this
only happens if legacy_ids_ is False.

References

.. _legacy_ids: https://docutils.sf.net/docs/user/config.html#legacy-ids

This is part of ongoing work in Docutils around better IDs:
https://sourceforge.net/p/docutils/bugs/207/
#8709

gmilde added 5 commits April 16, 2026 10:19
a) Ensure that enumerable elements (tables, figures and literal_blocks)
   have an ID. (In Docutils > 0.22, `nodes.document.note_implicit_target()`
   does not genereate an ID if `legacy_ids`_ is False.)

b) Title-derived IDs for enumerable elements:

   "Enumerable elements" get an auto-ID in the `AutoNumbering` SphinxTransform
   and a self-link (¶) after the caption/title in the HTML document.

   Currently, the ID is made of the "auto-id-prefix" + a running number
   (id1, id2, ...).  The generated IDs are not stable -- inserting/removing
   an enuerable element, footnote, or section with non-Lating heading will
   change the running number!

   Base the generated IDs on the caption or title text instead (similar to
   sections).  To avoid changed IDs when documents are re-compiled, this
   only happens if `legacy_ids`_ is False.

.. _legacy_ids: https://docutils.sf.net/docs/user/config.html#legacy-ids
Break long code line.
Delete whitespace around `:` binary operator.
This is the style expected by flake8 but fails upstream...
@gmilde

This comment was marked as outdated.

@jdillard jdillard added the docutils Tags upstream Docutils issues label Jun 12, 2026
@jfbu

jfbu commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

CHANGES.rst is still the 9.1.0-final version so I'll postpone this step.

Hi @gmilde, CHANGES.rst has since been updated, can you add an entry to it?

@jfbu jfbu added this to the 9.1.1 milestone Jun 27, 2026
@jdillard jdillard mentioned this pull request Aug 5, 2026
Comment thread CHANGES.rst Resolved
Comment thread sphinx/transforms/__init__.py Resolved
gmilde added 2 commits August 15, 2026 11:56
Fix typo and formatting issue (found by Jared Dillard).

Shorten CHANGES entry (keep changes list compact, without emtpy lines).

Try to solve the CI test failure with Python 3.12 and Docutils 0.21.
@gmilde

gmilde commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@jdillard Thank you for the feedback.

self.document.settings, 'legacy_ids', True
):
# cf. https://docutils.sf.net/docs/user/config.html#legacy-ids
node['names'].append(nodes.fully_normalize_name(refname))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing some context, but I reproduced a conflict with Docutils 0.23 and legacy_ids=False when a section title and table caption have the same text (Shared):

Shared
======

This reference should point to the section: `Shared`_.

.. table:: Shared

   ===  ===
   A    B
   ===  ===

With the same Docutils settings on the current master branch, `Shared`_ resolves to the section. With the updated AutoNumbering transform, Docutils reports the following error:

ERROR: Duplicate target name, cannot be used as a unique reference: "shared".

Is this behavior expected?

@gmilde gmilde Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the expected behaviour if we want "numbered captions" to become
Implicit Hyperlink Targets (i.e. behave like section titles).

IMV, the behaviour change is acceptable as it only happens after explicit user interaction (specifying the Docutils configuration setting legacy_ids which is new in Docutils 0.23) .
If the behaviour change is not wanted at this stage, we can drop it or decouple it from the fix for Docutils >= 0.23.

How would you link to the table caption in your example text with current Sphinx?

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

docutils Tags upstream Docutils issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants