✨ NEW: Add section_ref syntax extension (§1.1 heading references)#1170
Draft
chrisjsewell wants to merge 4 commits into
Draft
✨ NEW: Add section_ref syntax extension (§1.1 heading references)#1170chrisjsewell wants to merge 4 commits into
chrisjsewell wants to merge 4 commits into
Conversation
Wires the (unreleased) mdit-py-plugins section_ref plugin into MyST-Parser as a new optional extension. §1 / §1.1 / §2.3.4 references resolve, via a new ResolveSectionRefs transform, to internal links targeting the correspondingly numbered heading of the current document. Numbering is document-local and structural: with a single top-level heading, its subsections are §1, §2, ...; nested levels dot-separated. Unresolvable references stay as section-ref styled text and emit a suppressible myst.section_ref warning. References inside headings or link text are deliberately left unlinked, since a reference there would nest anchors in the output and in sphinx toctree entries. Requires mdit-py-plugins >= 0.7 (unreleased). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwRkZLzpbHdb3pgmctmn6H
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwRkZLzpbHdb3pgmctmn6H
The section_ref plugin now provides meta["numbers"] as a list of ints, so the marker attribute becomes section_numbers and the transform no longer parses the dotted string itself. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwRkZLzpbHdb3pgmctmn6H
Resolved §refs now carry the target section's title as reftitle, rendered by Sphinx HTML as a hover tooltip. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwRkZLzpbHdb3pgmctmn6H
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new optional syntax extension
section_ref, wiring in the new mdit-py-pluginssection_refplugin (executablebooks/mdit-py-plugins#144). It captures section-sign references —§1,§1.1,§2.3.4, the syntax LLMs commonly use to point at numbered headings — and resolves them to internal links targeting the correspondingly numbered heading of the current document:How it works
section_reftokens (withmeta["numbers"], the parsed section number as a list of ints);render_section_refproduces an inertnodes.inlinemarker carrying it as asection_numbersattribute.ResolveSectionRefstransform (priority 878 — deliberately beforeResolveAnchorIdsat 879 and Sphinx'sDoctreeReadEventat 880, soenv.titles/toctree collectors see resolved references) resolves markers document-locally and structurally: with a single top-level heading (the common# Titlelayout) its subsections are§1, §2, …; otherwise top-level headings are numbered; nested levels are dot-separated. This gives identical results in docutils (doctitle promotion) and Sphinx (no promotion), independent of:numbered:toctrees.refidto the section, classsection-ref), carrying the target heading's title as areftitle— rendered by Sphinx HTML as a hover tooltip. Unresolved ones stay as styled text plus a suppressiblemyst.section_refwarning.<a>elements in the output — and, for headings, inside Sphinx toctree entry links and docutils contents entries.Discussion points (why draft, beyond the release dependency)
env.toc_secnumbersfor:numbered:toctrees (cross-document, matches displayed numbers), falling back to structural numbering.# Title+ one## Sectiongets both promoted to title/subtitle by docutils in single-page mode, leaving no numbered sections (documented).Testing
section_refenabled in theextended_syntaxesregression build (heading ref stays inert in title/toc, body refs resolve with tooltips) — append-only fixture changes.🤖 Generated with Claude Code
https://claude.ai/code/session_01LwRkZLzpbHdb3pgmctmn6H