Skip to content

Support Docutils 1.0 doctest blocks and column widths - #14685

Open
devtejasx wants to merge 6 commits into
sphinx-doc:masterfrom
devtejasx:fix/docutils-1.0-doctest-colwidth-14680
Open

devtejasx wants to merge 6 commits into
sphinx-doc:masterfrom
devtejasx:fix/docutils-1.0-doctest-colwidth-14680

Conversation

@devtejasx

@devtejasx devtejasx commented Sep 16, 2026 •

Copy link
Copy Markdown

The new Docutils 1.0 changes how some document information is stored.
Doctest blocks now come in as a different type of node.
Table column widths are also stored as text instead of numbers.
Because of this, Sphinx could no longer find some doctest blocks correctly.
Tables also started causing problems in text, LaTeX, and Texinfo output.
The fix allows Sphinx to understand both the old and new doctest node types.
It also converts the table column widths from text back into numbers.
This keeps Sphinx working correctly with the new Docutils version.
The changes were tested with both Docutils 0.22 and 1.0.
Claude Code wrote the code, tests, and changelog; I reviewed everything, wrote the description, and submitted the change.

Docutils 1.0 represents native doctest blocks as literal_block nodes with
the pycon and doctest classes, and stores colspec colwidth values as strings.

Recognise the new doctest node when moving doctest blocks out of block
quotes, assigning a highlight language, marking translatable nodes and
collecting doctests. Convert colwidth values to integers in the text,
LaTeX and Texinfo writers, and create string colwidths in autosummary
tables on Docutils 0.22 and later.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this loses valid proportional widths. Docutils’ colspec.propwidth() can return a float, but this helper truncates it, so 2.5* becomes 2 and 0.5* becomes 0. That changes table ratios and can create zero-width columns. Could we preserve the proportion, or scale fractional values to integers, instead of int()-truncating it?

Docutils 1.0 allows a colspec's proportional width to be fractional.
Truncating with int() distorted the ratios between columns and turned
any width below 1 into a zero-width column.

Read the width exactly and scale every colspec in the tgroup by the
lowest common denominator of the table, so the proportions are
preserved. Tables that already use integer widths are unaffected.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rechecked current f3d1d2c. Fractional colwidths are now parsed exactly and scaled with a common denominator across sibling columns, so values such as 2.5*, 0.5* and unequal fractional widths keep their proportions instead of truncating or collapsing to zero. The added regression matrix covers the cases I raised. The two remaining red matrix jobs fail in an unrelated Python-domain rendering test, not the table-width code. My concern is resolved.

Master (d19cbb5) now handles Docutils 1.0 doctest blocks and string
colwidths itself, but converts colwidth with int(), which raises on
fractional or starred widths such as '2.5*'. Keep master's doctest
handling and use _get_colwidth() in the LaTeX, Texinfo and text writers.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for refreshing this against current master, Tejas. I checked the latest diff at 050c93e: the shared scaling still preserves the tested fractional and starred column-width ratios, and the Docutils/platform CI matrix is green. My earlier concern remains resolved. Happy to approve the refreshed head.

…ctest-colwidth-14680

# Conflicts:
#	CHANGES.rst
@devtejasx

Copy link
Copy Markdown
Author

Thanks for checking the refreshed head again, @sylvesterkaczmarek. CI is green on 30d111f. @AA-Turner, could you take a look when you have time?

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.

2 participants