Respect an explicit excerpt of 0 in page front-matter - #338
Open
Muhtasim-Munif-Fahim wants to merge 1 commit into
Open
Respect an explicit excerpt of 0 in page front-matter#338Muhtasim-Munif-Fahim wants to merge 1 commit into
Muhtasim-Munif-Fahim wants to merge 1 commit into
Conversation
`CheckFrontMatter` guarded the excerpt fallback with a truthiness check, so an explicit `:excerpt: 0` was indistinguishable from no excerpt at all and was overwritten with `post_auto_excerpt`. The first paragraph of the post then leaked into every `postlist` rendered with `:excerpts:`. The same option given to the `post` directive already behaved correctly, because `process_posts` guards the identical fallback with `is None`. This aligns the front-matter path with that behaviour. Adds `roots/test-excerpt` and `test_excerpt.py` covering the explicit 0, a non-zero count, the absent-value fallback, and an explicit 0 against a non-default `post_auto_excerpt`. The first and last fail without this change. Fixes sunpy#317 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #317.
The bug
CheckFrontMatterguards the excerpt fallback with a truthiness check:0is falsy, so an explicit:excerpt: 0is indistinguishable from no excerpt at all and gets overwritten withpost_auto_excerpt. The first paragraph of the post then leaks into everypostlistrendered with:excerpts:, which is what #317 describes.The same option given to the
postdirective already behaves correctly, becauseprocess_postsguards the identical fallback withis None:So the two ways of declaring a post disagree. This aligns the front-matter path with the directive path.
Reproduction
Two posts, identical except for how the excerpt is declared:
Before this change the directive post correctly renders no excerpt, while the front-matter post renders its first paragraph. After, both render nothing.
Tests
Adds
roots/test-excerptandsrc/ablog/tests/test_excerpt.pycovering four cases:0suppresses the excerpt,post_auto_excerpt,0wins over a non-defaultpost_auto_excerpt.The first and last fail without the one-line change; the middle two are controls that pass either way. Full suite is 13 passed on Sphinx 9.1.0.
One note
The new tests carry a
filterwarningsmark:CheckFrontMatterreaches the app throughSphinxTransform.app, which Sphinx 9 deprecates (the replacement is the privateenv._app). Since the suite turns warnings into errors, any test exercising the front-matter path trips it. That is a pre-existing compatibility issue orthogonal to this bug, and migrating to a private attribute felt like your call rather than something to smuggle into a bugfix — happy to fold it in here or open a separate issue, whichever you prefer.🤖 Generated with Claude Code