Skip to content

Fix directive body_offset inflated by one when body ends in blank lines - #1179

Open
dchaudhari7177 wants to merge 2 commits into
executablebooks:masterfrom
dchaudhari7177:fix/body-offset-trailing-blank
Open

Fix directive body_offset inflated by one when body ends in blank lines#1179
dchaudhari7177 wants to merge 2 commits into
executablebooks:masterfrom
dchaudhari7177:fix/body-offset-trailing-blank

Conversation

@dchaudhari7177

Copy link
Copy Markdown

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_options returns the body as a string built with "\n".join(...), and parse_directive_text re-split it and derived the offset as len(content.splitlines()) - len(body_lines). The join→split round-trip drops exactly one trailing blank line, so len(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_options now reports the number of source lines the option block actually occupies (computed before the body is re-joined), and parse_directive_text uses 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_lines covering colon- and YAML-style option blocks, with and without trailing blanks — it fails on main and passes here. The full test_parse_directives.py suite (including the snapshot fixtures and the trailing-closing-text case) stays green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant