From c19a0d3f1201eaaafc16a01d831436d8166a23a9 Mon Sep 17 00:00:00 2001 From: vishalkaay Date: Tue, 3 Nov 2026 22:17:02 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20count=20lines,=20not=20ch?= =?UTF-8?q?aracters,=20for=20`{include}`=20`:start-after:`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `:start-after:` option added the character index of the end of the marker to `startline`, which counts lines. Every line of the included content, and every warning raised in it, was shifted by the number of characters before the marker. Add the number of newlines consumed before the slice instead, and cover `:start-after:` alone and combined with `:start-line:` in the include error fixtures. Fixes #1216 --- myst_parser/mocking.py | 2 +- .../fixtures/mock_include_errors.md | 19 +++++++++++++++++++ .../test_renderers/test_include_directive.py | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/myst_parser/mocking.py b/myst_parser/mocking.py index b65888e7..20c786c9 100644 --- a/myst_parser/mocking.py +++ b/myst_parser/mocking.py @@ -442,7 +442,7 @@ def run(self) -> list[nodes.Element]: f'Directive "{self.name}"; option "{split_on_type}": text not found "{split_on}".', ) if split_on_type == "start-after": - startline += split_index + len(split_on) + startline += file_content[: split_index + len(split_on)].count("\n") file_content = file_content[split_index + len(split_on) :] else: file_content = file_content[:split_index] diff --git a/tests/test_renderers/fixtures/mock_include_errors.md b/tests/test_renderers/fixtures/mock_include_errors.md index 6e443cb6..fa259ede 100644 --- a/tests/test_renderers/fixtures/mock_include_errors.md +++ b/tests/test_renderers/fixtures/mock_include_errors.md @@ -21,3 +21,22 @@ Error in include file: . tmpdir/bad.md:2: (WARNING/2) Unknown interpreted text role "a". [myst.role_unknown] . + +Error in include file with start-after: +. +```{include} bad_after.md +:start-after: START-HERE +``` +. +tmpdir/bad_after.md:5: (WARNING/2) Unknown interpreted text role "a". [myst.role_unknown] +. + +Error in include file with start-line and start-after: +. +```{include} bad_after.md +:start-line: 1 +:start-after: START-HERE +``` +. +tmpdir/bad_after.md:5: (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..008f6323 100644 --- a/tests/test_renderers/test_include_directive.py +++ b/tests/test_renderers/test_include_directive.py @@ -41,6 +41,9 @@ 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_after.md").write_text( + "line one\nline two\nSTART-HERE\nline four\n{a}`b`" + ) report_stream = StringIO() publish_doctree(