Fix line attribution inside included markdown being off by one - #1184
Open
dchaudhari7177 wants to merge 1 commit into
Open
Fix line attribution inside included markdown being off by one#1184dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
MockIncludeDirective.run passed `startline + 1` to nested_render_text, but that lineno is added to the 0-based token maps *before* _render_tokens applies its own 0-based to 1-based conversion. The offset of the first included line is `startline`, already 0-based, so every warning raised inside an included file was reported one line too low. The existing "Error in include file" fixture encoded the off-by-one: bad.md holds the role on line 1 and the expectation read `bad.md:2`. Fixes executablebooks#1165
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 #1165.
Cause
MockIncludeDirective.runcalls:nested_render_textadds thatlinenoto the 0-based token maps, and_render_tokensthen applies its own 0-based → 1-based+ 1.startlineis already the 0-based offset of the first included line, so adding one here reports every warning inside an included file one line too low. Exactly as diagnosed in the issue — a one-token change.The existing fixture encoded the bug
tests/test_renderers/fixtures/mock_include_errors.mdexpected:while
bad.mdis written as"{a}b"— a single line. That expectation is now:1.Regression cases
The issue asked for these before touching the line, so the fixture gains five more, each with the offending role in a paragraph of its own (MyST attributes an inline warning to its enclosing block's start line, which is worth being deliberate about here):
bad_line3.md:3bad_line3.md:3:start-line: 2bad_skipped.md:4bad_frontmatter.md:5bad_inner.mdviabad_outer.md:3All six cases fail on
masterand pass with the change — I checked by reverting onlymocking.pyand leaving the tests in place.The nested case is worth calling out: before this change it appeared correct for a role sharing a paragraph with the preceding line, because the two errors cancelled. Putting the role in its own paragraph shows it was off by one like the rest.
:heading-offset:was also probed and is unaffected (heading offsetting shifts levels, not maps), as is front-matter stripping — thefront_mattertoken is popped before the maps are adjusted, so it shifts nothing.Test run
1240 passed, 18 skipped. Three failures are pre-existing on an unmodified checkout in this environment (test_cmdline[40-linkify],test_extended_syntaxes,test_extended_syntaxes_text) — I diffed theFAILEDsets before and after, and those three are identical on both sides.🤖 Generated with Claude Code