Skip to content

code block custom ID is not respected when highlighting lines #6448

@hellt

Description

@hellt

Context

No response

Bug description

I am in love with the way one can link to certain line numbers from the markdown:

Here we [handle the `version`](#__codelineno-8-2:9) CLI flag.

The problem I am having is that codelineno-8-2:9 is not a persisten id of the code block element.

If we add a code block before the one in question, its ID will auto-increment and the link won't work anymore.

Since pymarkdownx snippet extension allows to assign user-defined ID it is possible to have a static reference to the code block, that is agnostic to the document layout.

``` {.python #myid linenums="1"}
import bar
```

The problem is that #myid id assigned to the code block is not "respected" by the mkdocs-material, so that when one uses #__codelineno-myid-7 the relevant line does not get highlighted, although the span elements have that ID.

Related links

Reproduction

9.4.14+insiders.4.46.0-code-block-custom-id.zip

Steps to reproduce

launch the reproduction, open /blog/2023/11/11/bar/ page and click on the links at the bottom of the page.

Browser

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions