Skip to content

footnotes markdown extension fails validation #3919

Closed

Description

@juntyr

In https://github.com/juntyr/numcodecs-rs, I use footnotes for one of the Python packages. Building MkDocs in strict mode gives the following messages:

INFO    -  Doc file 'api/numcodecs_wasm_random_projection/index.md' contains a link '#numcodecs_wasm_random_projection.RandomProjection--fn:1', but there is no
           such anchor on this page.
INFO    -  Doc file 'api/numcodecs_wasm_random_projection/index.md' contains a link '#numcodecs_wasm_random_projection.RandomProjection--fn:2', but there is no
           such anchor on this page.
INFO    -  Doc file 'api/numcodecs_wasm_random_projection/index.md' contains a link '#numcodecs_wasm_random_projection.RandomProjection--fnref:1', but there is no
           such anchor on this page.
INFO    -  Doc file 'api/numcodecs_wasm_random_projection/index.md' contains a link '#numcodecs_wasm_random_projection.RandomProjection--fnref:2', but there is no
           such anchor on this page.

These links are the forward and backward links of the footnotes.

Activity

  1. pawamoy commented on Feb 3, 2025

    @pawamoy
    Contributor

    Hey @juntyr, thanks for the report. I tried building your docs but I'm getting missed cross-reference warnings instead of info logs about footnotes. Could you try to provide a minimal reproduction example?

  2. juntyr commented on Feb 3, 2025

    @juntyr
    Author

    I created https://github.com/juntyr/mkdocs-footnotes which provides the following build output - there are footnotes both in the index.md and api.md files.

    INFO    -  Cleaning site directory
    INFO    -  Building documentation to directory: /workspaces/mkdocs-footnotes/site
    INFO    -  Doc file 'api.md' contains a link '#pkg.Cls--fn:1', but there is no such anchor on this page.
    INFO    -  Doc file 'api.md' contains a link '#pkg.Cls--fnref:1', but there is no such anchor on this page.
    INFO    -  Documentation built in 0.23 seconds
    
  3. pawamoy commented on Feb 3, 2025

    @pawamoy
    Contributor

    Thanks, I was able to reproduce the issue you describe. What's weird is that the info logs disappear in verbose mode. Probably because of this line:

    if log.getEffectiveLevel() > logging.DEBUG:

    Not sure to understand why we have this line. Surely enabling verbose mode doesn't mean we want anchor validation to be disabled.

    The reproduction indicates the culprit is mkdocstrings, and upon investigation, I think it is indeed, because when creating a new, inner Markdown instance to render docstrings, it registers MkDocs' _RelativePathTreeprocessor again, but using the same instance, not a new one. So when mkdocstrings converts the docstring, it populates the relpath processor's links_to_anchors attribute, which is then assigned to the page's own links_to_anchors attribute:

    self.links_to_anchors = relative_path_ext.links_to_anchors

    Then later MkDocs runs validation and boom, footnotes generated by mkdocstrings' inner Markdown instance are iterated on in the upper MkDocs level, where MkDocs wasn't able to extract anchors from mkdocstrings' generated HTML.

    I suppose the easiest fix (and probably correct fix too) is to create a new instance of the relpath processor in mkdocstrings.

  4. pawamoy commented on Feb 3, 2025

    @pawamoy
    Contributor

    Fixed in mkdocstrings, will release soon.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions