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(