Skip to content

Line attribution inside {include}d markdown is off by one #1165

Description

@chrisjsewell

Found while probing #1164 (which does not change this behaviour — it is identical before and after).

All warnings/errors raised inside an {include}d markdown file are attributed one line too low. E.g. with sub.md:

line one

{unknownrole}`x`

included via ```{include} sub.md — the role warning reports sub.md:4, but the role is on line 3.

Cause

MockIncludeDirective.run calls:

self.renderer.nested_render_text(file_content, startline + 1, ...)

(myst_parser/mocking.py) but nested_render_text's lineno is added to the 0-based token maps before _render_tokens applies its own 0-based → 1-based + 1 conversion, so the correct argument for a file starting at (1-based) line startline + 1 is startline, not startline + 1. Every other caller (MockState.nested_parse) passes a value that composes correctly.

The fix is likely a one-character change, but wants a warning-line regression test for: a plain include, :start-line:, and nested includes, before touching it — the include-with-:heading-offset: and front-matter-stripping paths (front_matter token pop shifts nothing since maps are preserved) should be probed too.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions