Skip to content

Fix mkdocstrings cross-references not resolving to links in Zensical-built docs#4

Open
Copilot wants to merge 7 commits intomasterfrom
copilot/add-website-links-references
Open

Fix mkdocstrings cross-references not resolving to links in Zensical-built docs#4
Copilot wants to merge 7 commits intomasterfrom
copilot/add-website-links-references

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 9, 2026

Zensical never calls fix_refs() from mkdocs-autorefs, so every <autoref> tag emitted by mkdocstrings (type signatures, base classes, return types, user-written [identifier][] refs) was left as raw, unlinked HTML in the built site.

Changes

  • scripts/fix_autorefs.py — New post-build script that resolves all <autoref> tags, written using pyochain iteration patterns (consistent with the other scripts in this folder):

    • Pass 1: scans all site/ HTML to build an anchor-ID → absolute-URL map using pc.Iter(...).flat_map(...).for_each_star(...)
    • Extends the map with module-alias entries discovered via Python introspection (e.g. pyochain.traits.PyoIterator → canonical pyochain.traits._iterable.PyoIterator), using filter_map, flat_map, filter_star, and for_each_star
    • Pass 2: rewrites every <autoref> to <a class="autorefs autorefs-internal"> with a correct relative URL; falls back to the parent class anchor for attribute refs (Err.errorErr); emits a rich warning (with page URL) for non-optional unresolved refs
    • Uses rich/rich.text for all output, consistent with other scripts
  • zensical.toml — Registers mkdocs_autorefs._internal.references:AutorefsExtension as a markdown extension, enabling [identifier][] / [label][identifier] cross-reference syntax in plain .md pages, not just inside ::: docstring blocks

  • .github/workflows/docs.yml — Runs fix_autorefs.py between zensical build and the GitHub Pages deploy step

  • scripts/rebuild-docs.ps1 — Updated to run fix_autorefs.py after the build

  • docs/api-reference.md — Migrated all type links to cross-reference syntax (e.g. [`Iter[T]`][pyochain._iter.Iter])

Usage example

<!-- in any .md page -->
[`Iter[T]`][pyochain._iter.Iter] lazily wraps any iterable.
[pyochain.rs.Option][] is returned by methods that may produce no value.

Both forms now resolve to clickable links after zensical build && uv run scripts/fix_autorefs.py.

Copilot AI linked an issue Apr 9, 2026 that may be closed by this pull request
@OutSquareCapital
Copy link
Copy Markdown
Owner

Would like to add details:

  • it concerns the documentation website
  • we use zensical to build it, relevant info is in the pyproject for the config
  • there's a bash script in the scripts folder and a github workflow related to building it

Copilot AI and others added 4 commits April 9, 2026 21:25
Agent-Logs-Url: https://github.com/OutSquareCapital/pyochain/sessions/ae1f437f-4e75-4afb-a797-a5d4be62346e

Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
…on, and docs updates

Agent-Logs-Url: https://github.com/OutSquareCapital/pyochain/sessions/ae1f437f-4e75-4afb-a797-a5d4be62346e

Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
…ed ref handling, simplify rebuild script

Agent-Logs-Url: https://github.com/OutSquareCapital/pyochain/sessions/ae1f437f-4e75-4afb-a797-a5d4be62346e

Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
Copilot AI changed the title [WIP] Add website links to improve navigation experience Fix mkdocstrings cross-references not resolving to links in Zensical-built docs Apr 9, 2026
Copilot AI requested a review from OutSquareCapital April 9, 2026 21:41
- [Interoperability](interoperability.md): convert between types with various methods
- [Examples & Cookbook](examples.md): practical patterns and concrete examples

## Cross-references
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole section is irrelevant. Getting started is for end users, not for internal devs

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 2ec6231getting-started.md is back to its original state.

@@ -0,0 +1,309 @@
"""Post-process the built site to resolve mkdocstrings cross-reference tags.

Zensical does not call ``fix_refs`` from ``mkdocs-autorefs``, so the
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole file need to follow pyochain patterns for iterations, just like the other scripts

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten in 2ec6231 using the same patterns as the other scripts (generate_docs.py, check_docstrings.py). Key changes:

  • import pyochain as pc + import rich/rich.text
  • _file_anchors() and _module_aliases() return pc.Iter[...]
  • _class_alias() and _try_import_module() return pc.Option
  • All manual loops replaced with pc.Iter(...).flat_map(...), .filter_map(...), .filter_star(...), .map_star(...), .for_each_star(...), .collect(), .sum(), .length()

@@ -83,3 +83,5 @@
custom_fences = [
{ name = "mermaid", class = "mermaid", format = "pymdownx.superfences.fence_code_format" },
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this change been made?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AutorefsExtension enables [text][identifier] and [identifier][] cross-reference syntax in regular markdown pages (like api-reference.md). Without it, [``Iter[T]``][pyochain._iter.Iter] in a .md file would be treated as a broken markdown reference link and rendered as plain text. With the extension, zensical's markdown processing converts these into <autoref> tags, which fix_autorefs.py then resolves to proper <a> links.

If you'd prefer not to use this syntax in the markdown docs, the extension can be removed and api-reference.md can be reverted to plain links — let me know.

@OutSquareCapital OutSquareCapital marked this pull request as ready for review April 9, 2026 23:20
@OutSquareCapital
Copy link
Copy Markdown
Owner

@copilot act on my review comments

Copilot AI and others added 2 commits April 9, 2026 23:31
…py with pyochain patterns

Agent-Logs-Url: https://github.com/OutSquareCapital/pyochain/sessions/22463733-e40a-47a5-9090-ca23ca661686

Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
…f syntax, improve lambda readability, rename counts variable

Agent-Logs-Url: https://github.com/OutSquareCapital/pyochain/sessions/22463733-e40a-47a5-9090-ca23ca661686

Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Website links

2 participants