From 7791b323c0c1e1e7d257b55d32c8941b43c65661 Mon Sep 17 00:00:00 2001 From: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com> Date: Tue, 14 Jul 2026 17:22:31 -0700 Subject: [PATCH] FIX: Correct included source line attribution Included Markdown applied a one-based offset before token maps were converted to one-based source lines, shifting every diagnostic down by one line. Pass the zero-based start line to the nested renderer and cover plain, start-line, and nested includes. Tests: python -m pytest -q Fixes #1165 --- myst_parser/mocking.py | 2 +- .../fixtures/mock_include_errors.md | 19 ++++++++++++++++++- .../test_renderers/test_include_directive.py | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/myst_parser/mocking.py b/myst_parser/mocking.py index f809c6d7..75d4beba 100644 --- a/myst_parser/mocking.py +++ b/myst_parser/mocking.py @@ -515,7 +515,7 @@ def run(self) -> list[nodes.Element]: ) self.renderer.nested_render_text( file_content, - startline + 1, + startline, heading_offset=self.options.get("heading-offset", 0), ) finally: diff --git a/tests/test_renderers/fixtures/mock_include_errors.md b/tests/test_renderers/fixtures/mock_include_errors.md index 6e443cb6..6474a1be 100644 --- a/tests/test_renderers/fixtures/mock_include_errors.md +++ b/tests/test_renderers/fixtures/mock_include_errors.md @@ -19,5 +19,22 @@ Error in include file: ```{include} bad.md ``` . -tmpdir/bad.md:2: (WARNING/2) Unknown interpreted text role "a". [myst.role_unknown] +tmpdir/bad.md:1: (WARNING/2) Unknown interpreted text role "a". [myst.role_unknown] +. + +Error in include file with start line: +. +```{include} bad_start.md +:start-line: 1 +``` +. +tmpdir/bad_start.md:2: (WARNING/2) Unknown interpreted text role "a". [myst.role_unknown] +. + +Error in nested include file: +. +```{include} outer.md +``` +. +tmpdir/bad.md:1: (WARNING/2) Unknown interpreted text role "a". [myst.role_unknown] . diff --git a/tests/test_renderers/test_include_directive.py b/tests/test_renderers/test_include_directive.py index 9f03d633..5aee3206 100644 --- a/tests/test_renderers/test_include_directive.py +++ b/tests/test_renderers/test_include_directive.py @@ -41,6 +41,8 @@ def test_errors(file_params, tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) tmp_path.joinpath("bad.md").write_text("{a}`b`") + tmp_path.joinpath("bad_start.md").write_text("skip\n{a}`b`") + tmp_path.joinpath("outer.md").write_text("```{include} bad.md\n```") report_stream = StringIO() publish_doctree(