Skip to content

🐛 Show button line blocks as separate lines - #308

Merged
chrisjsewell merged 12 commits into
executablebooks:mainfrom
Cherith1222:fix/156-button-line-block
Nov 9, 2026
Merged

chrisjsewell merged 12 commits into
executablebooks:mainfrom
Cherith1222:fix/156-button-line-block

Conversation

@Cherith1222

Copy link
Copy Markdown
Contributor

button-link parsed its body with inline_text, so an RST line block kept the | characters and did not break the lines. Bars indented one column past an option such as :expand: were parsed as a block quote around that line block, which is the markup in #156. Those bars are now separate lines, and a blank line between two bars is handled the same way. button-ref uses the same content path.

CHANGELOG.md has an Unreleased entry for this fix.

Fixes #156.

This pull request was drafted with assistance from Cursor. The account owner confirmed it before it was submitted.

Cherith1222 and others added 12 commits October 8, 2026 06:34
button-link parsed its body as inline text, so an RST line-block bar stayed on the page. Bars indented under an option were parsed as a block quote and still kept the bar.

AI-assisted (Cursor). The account owner confirmed this can be submitted.
AI-assisted (Cursor). The account owner confirmed this can be submitted.
Follow docutils' line-block syntax: the first non-blank line must start
with "|" and then a space (or end there). Text that starts with a
substitution ("|sub| text") is then parsed once, as before, instead of
twice: the second parse duplicated side effects, such as an autonumbered
footnote reference ("Too many autonumbered footnote references").
Continuation lines are now accepted too. MyST text is never
block-parsed: line blocks are RST syntax, and the extra parse reported
MyST's warnings twice.

Move the parsed inline nodes into the button rather than copying them:
docutils registers footnote references on the document, so a copied one
was never numbered and crashed the HTML writer (KeyError: 'refid').

The tests cover button-link and button-ref, the markup from executablebooks#156, a
blank line between bars, continuation lines, nested lines and inline
markup.
A raw HTML <br> is dropped by the LaTeX, text, man and texinfo writers,
which then joined the lines ("heynew line"). Use an sd_line_break node
instead: <br /> in HTML, \newline{} in LaTeX (it compiles inside
\sphinxhref with pdflatex and xelatex), and a space in the other
builders and in astext().
The whole button was one gettext message, and its text ran the lines
together. Each line is now a message of its own, as in a normal line
block (msgids "hey" and "new line"), and each translated line keeps its
place.
An RST line block, or a MyST hard line break (a backslash at the end of
the line). The live example also puts the LaTeX line break through the
PDF build.
Check every line at the outermost indent, not only the first one, so that
a line block followed by a paragraph is parsed once, as inline text,
instead of being block-parsed and then parsed again (which repeated
messages, raised a spurious "Too many autonumbered footnote references"
and registered substitution definitions document-wide).
Before docutils 0.22 (Sphinx 7 and 8 here) the lines of a parsed line
block have no source info, and Sphinx extracts no message from a
translatable node without a source, so a multi-line button could not be
translated. Give such lines the source and line of the button's first
content line.
docutils puts the system messages of a line's inline markup (an unknown
role, or a role found only through the English fallback) beside the
line block, so the button fell back to inline text and parsed the text
a second time: the message was reported twice, an autonumbered footnote
reference failed, and the bars were kept. The messages are now ignored
when checking for line blocks; they have already been reported.
@chrisjsewell
chrisjsewell merged commit a166cd9 into executablebooks:main Nov 9, 2026
25 checks passed
chrisjsewell added a commit to dipinknair/sphinx-design that referenced this pull request Nov 9, 2026
chrisjsewell added a commit that referenced this pull request Nov 9, 2026
…ils does

The splitter stripped every continuation line, and kept the empty first
line of a bare bar. docutils (and so #308's block parse) strips only the
common indent of the continuation lines, so they keep their indent relative
to each other, and drops a bare bar's empty first line. A continuation line
indented deeper than the one before it therefore lost its leading spaces in
text, HTML, LaTeX, man and .pot output, and `|` followed by a continuation
line gained a leading newline. Both now match main and docutils.
chrisjsewell added a commit that referenced this pull request Nov 9, 2026
Three comments in the #308 tests still described the removed block parse
(nodes moved out of it, messages placed beside the line block, a source
fallback for docutils < 0.22). Their assertions are unchanged.
chrisjsewell added a commit that referenced this pull request Nov 10, 2026
#308 (by @Cherith1222) made an RST line block in button text render as separate lines (#156), by block-parsing the text and falling back to inline markup when the result was not only line blocks. That fallback parsed malformed bodies twice, with spurious footnote, block-quote, duplicate-target and leaked-substitution messages. The lines are now found textually and each is parsed once with inline_text, into its own gettext message, with the text docutils gives it (continuation lines keep their relative indent, and whitespace after the bar such as a no-break space is kept); any other text is parsed once as inline markup, as before #308. Valid line blocks give byte-identical HTML, LaTeX, text, man, texinfo and .pot output on Sphinx 7.4, 8.2 and 9.1, except that .pot locations on docutils < 0.22 now name each line rather than the first; malformed bodies match the pre-#308 output.

The inline path also no longer counts the lines before a button twice in RST: messages and gettext locations for button text now name its first content line (they named a later line, a line past the end of the file inside a dropdown, and the including page for a button in an included file). MyST is unchanged.

The docs note on multi-line button text now says that a MyST hard line break only breaks the line in HTML and LaTeX (other builders join the lines or print the raw break markup), and points translated projects at the RST line block (via eval-rst in MyST). It also says that, in RST, a one-line label that starts with "| " (or is a bare "|") is a one-line line block whose leading bar is not shown (so `| Docs | API |` reads "Docs | API |"), and that a literal leading bar is written `\|`; a test pins both.
@chrisjsewell

Copy link
Copy Markdown
Member

Merged in a166cd9, thanks @Cherith1222, and sorry for the wait! Before merging I pushed fix-ups so that line blocks in button text work beyond the HTML tests: the parsed nodes are moved rather than copied (a copied footnote reference crashed the HTML writer); a new sd_line_break node renders as <br /> in HTML, \newline{} in LaTeX and a space in text, man and texinfo; each line is its own translation message; and there is a short docs note.

After merging we found one more class of problem in the parse-then-fall-back approach: text that looked like a line block at its outermost indent but was not only one got parsed twice, with spurious footnote, block-quote and duplicate-target messages. #315 (beaa044) now finds the lines textually and parses each one once, before any of this is released. Your sd_line_break node, the per-line gettext messages, the docs and the tests all stay as they were.

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.

New line in button -- not working

2 participants