Skip to content

docs: autorefs warning about rst reference #1495

Closed
@pawamoy

Description

@pawamoy

From #1494 (comment):

  • when rendering API docs, we enable automatic summaries (summary: true in mkdocs.yml)
  • previously this was an Insiders feature, and it was recently made available to everyone, so it's now active in this project too
  • when we render the extensions sub-package, we summarize each submodule
  • to summarize items, we render the first line of their docstring
  • in the case of the admonition module, its first line contains a reference: [rST][]
  • since we only render this first line, the reference is unresolved by Python-Markdown itself, and autorefs kicks in (and fails too)

Possible solutions:

  • don't use "defered inline references" (not sure what to call them) in docstrings summaries (the first line) and instead put their URL directly within them (so [rST](https://...) instead of [rST][]), or move them lower, into the docstring body
  • use pymdownx.snippets to auto-append references at the end of each markdown document (done on the fly, no modification to any file, except maybe to remove all refs from everywhere and gather them in the single auto-appended file, see https://facelessuser.github.io/pymdown-extensions/extensions/snippets/#auto-append-snippets)
  • disable auto-summaries

Answering to #1494 (comment):

As an aside, if you are rendering a partial document, then you need to account for reference links and properly render them. IMO there should be no requirement that the document author needs to account for this and alter the way links are formatted.

If we want to account for references, then we'll have to parse (actually convert) the whole document (docstring) with Python-Markdown, then only keep the HTML part we're interested in, which in this case is the first line. Not sure how much sense "first line" makes in HTML. It would probably translate as "first paragraph". Which if we want to do in a robust manner, would mean either parsing HTML again, or using a temporary Python-Markdown extension (probably a tree processor) that prunes everything after the first paragraph. This could be wasteful too (converting the whole document just to get rid of most of it). Not sure if there are ways to make this more efficient.

  1. Reference links are resolved.

Implies the above.

  1. Links are striped from summaries and only the label text is included.

Doesn't seem possible. The non-natively-resolved reference could a valid autorefs cross-reference. In this case we do want the warning.

I'd be tempted to say that this is a limitation of the summary feature, and that users should account for it rather than the opposite. The same thing happens for rendering docstring sections by the way, since docstrings written following the Google-style or Numpydoc-style will be split into sections (and sections into items), and each section (item description) will be rendered separately, meaning each section (item) must include its own references and footnotes for them to resolve.

Maybe there'd be yet another way for us to inject ourselves into the conversion process with an extension, in order to collect references and footnotes, but our integration with Python-Markdown is already quite complicated so I'm reluctant to complicate it further.

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