gh-135828: Disable syntax highlighting in Using Python on macOS - #150074
Conversation
The page uses parsed-literal blocks for shell snippets so that `|version|` substitutions work. Without an explicit highlight language, Sphinx applies the project default (`python3`), which makes the Pygments python3 lexer choke on tokens like `$` in the shell examples. The English build silently retries in relaxed mode, but translated builds (e.g. python-docs-pt-br) surface this as `misc.highlighting_failure` warnings and add an unwanted highlight to the rendered output. Add `.. highlight:: none` at the top of the file, matching the pattern already used by `Doc/using/windows.rst` and `Doc/using/editors.rst`. The English HTML output is unchanged (the page already rendered without highlight thanks to the lexer fallback) and the translation builds no longer produce the warning.
hugovk
left a comment
There was a problem hiding this comment.
Thanks, this seems like a reasonable fix.
If we ever want to apply highlighting on this page, we can move . highlight:: none just before .. parsed-literal:: and reset like .. highlight:: python3 afterwards.
@picnixz I guess the longer-term fix is for Sphinx not to apply highlighting to parsed-literal?
|
Looks like sphinx-doc/sphinx#12287 is the upstream Sphinx bug, and sphinx-doc/sphinx#12238 is a stalled PR to fix it. |
|
Thanks @Taeknology for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-154958 is a backport of this pull request to the 3.15 branch. |
|
GH-154959 is a backport of this pull request to the 3.14 branch. |
|
GH-154960 is a backport of this pull request to the 3.13 branch. |
Problem
Doc/using/mac.rsthas no top-level.. highlight::directive, sothe project default from
Doc/conf.py(highlight_language = 'python3')is applied. The page only contains
parsed-literalblocks for shellsnippets — these need
parsed-literalso that|version|substitutionswork (added in #130400). With the
python3lexer active, Pygmentschokes on tokens like
$in the shell examples.In English builds Pygments silently retries in relaxed mode, so nothing
visible breaks. In translated builds (e.g.
python-docs-pt-br)
the failure surfaces as
misc.highlighting_failurewarnings, and thetranslated page even renders the shell snippets with syntax highlighting
plus red error rectangles around
$.Fix
Add
.. highlight:: noneat the top ofDoc/using/mac.rst, matchingthe pattern already used by
Doc/using/windows.rstandDoc/using/editors.rst. This prevents thepython3lexer from beingapplied to the
parsed-literalblocks while keeping the|version|substitutions intact.
Verification
Pygments python3 lexer fails on
$(root cause confirmed).Running the lexer directly on a representative shell snippet from
the page yields three
Token.Error '$'tokens:English HTML output is unchanged. Built
Doc/using/mac.htmlfrom
upstream/main(baseline) and from this branch, then diffed:The only difference is the build timestamp. Body content is
identical, so existing English readers see exactly the same page.
Builds succeed. Both baseline and the fix produce
build succeeded, 1 warning.The single warning is the well-knownpartial-build search index notice ("색인이 불완전합니다") emitted
when building a single file, and is unrelated to this change.
Pattern parity with sibling files. The directive matches what
Doc/using/windows.rst:1andDoc/using/editors.rst:1already do.Reproducing the original translation-side warning requires a translated
build (e.g. the
python-docs-pt-brrepository), but the root cause isthe
python3lexer being applied to shell text — items (1) and (4)remove that cause directly, so the symptom cannot recur regardless of
language.