Repository navigation
Fix directive body_offset inflated by one when body ends in blank lines - #1179
Merged
chrisjsewell merged 7 commits intoNov 9, 2026
Merged
chrisjsewell merged 7 commits into
chrisjsewell merged 7 commits into
Conversation
…es end to end Parametrise the body_offset unit test (one trailing blank, a blank separator line, text after the closing `---`, an unclosed `---` block, and first-line content with and without options), and add an end-to-end test that body paragraphs and their warnings land on their source lines.
…n paths Adds trailing-blank cases for validate_options=False (the plain-YAML path myst-nb uses) and for docutils' test directive, whose option results return through their own branches. Also rewords the option_line_count docstring (it counts the lines before the body, which is one fewer than the block when text trails a closing `---`) and wraps the new comments.
Member
|
Merged in 56849d1, thanks @dchaudhari7177, the fix was right: counting the option-block lines before the body is re-joined is the correct place to do it. Before merging I pushed two merges of
With |
This was referenced Nov 10, 2026
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 #1177.
body_offset(the number of lines from a directive's opening line to its first body line) was inflated by one whenever a directive had an option block and its body ended in blank line(s)._parse_directive_optionsreturns the body as a string built with"\n".join(...), andparse_directive_textre-split it and derived the offset aslen(content.splitlines()) - len(body_lines). The join→split round-trip drops exactly one trailing blank line, solen(body_lines)was one short and the offset one too high — every body element was then reported one source line too low.Fix:
_parse_directive_optionsnow reports the number of source lines the option block actually occupies (computed before the body is re-joined), andparse_directive_textuses that directly instead of the lossy subtraction. The count also correctly handles a---closer that carries trailing text (which becomes the first body line on the closing line itself).Verification
Added
test_body_offset_not_inflated_by_trailing_blank_linescovering colon- and YAML-style option blocks, with and without trailing blanks — it fails onmainand passes here. The fulltest_parse_directives.pysuite (including the snapshot fixtures and the trailing-closing-text case) stays green.