Add support for cross-document references#79
Conversation
Implement :doc:/:ref:/:confval:/etc. cross-references in the Typst builder, following the same approach as Sphinx's LaTeX builder: all documents are merged into a single doctree, and Sphinx's standard env.resolve_references() runs against that merged tree right after merging. This lets Sphinx's own domains handle path normalization, label lookup, title substitution, and intersphinx exactly as they do for any other builder. Builder.get_target_uri()/get_relative_uri() map a docname onto the single merged Typst document, mirroring the LaTeX builder's "%docname" convention. The writer's job is then only to translate the refid/refuri that Sphinx resolves into a namespaced Typst label (<docname:id>); the namespace keeps ids from colliding across documents now that they all share one output file. A small per-document "#metadata(none) <label>" anchor - the same trick HTML uses for an extra empty anchor per additional id on an element - gives whole-document :doc: references something to link to even when the target document has no sections, and covers section/signature ids beyond the first, since Typst only allows one label per element. Includes test coverage for basic cross-references, :ref: to named targets, relative paths (including bare relative paths resolved from the referring document's directory), nested documents, and edge cases such as documents without sections and confval-style targets.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughThis PR implements cross-reference support for the merged single-file Typst builder. In Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Implement :doc:/:ref:/:confval:/etc. cross-references in the Typst
builder, following the same approach as Sphinx's LaTeX builder: all
documents are merged into a single doctree, and Sphinx's standard
env.resolve_references() runs against that merged tree right after
merging. This lets Sphinx's own domains handle path normalization,
label lookup, title substitution, and intersphinx exactly as they do
for any other builder.
Builder.get_target_uri()/get_relative_uri() map a docname onto the
single merged Typst document, mirroring the LaTeX builder's
"%docname" convention. The writer's job is then only to translate the
refid/refuri that Sphinx resolves into a namespaced Typst label
(docname:id); the namespace keeps ids from colliding across
documents now that they all share one output file. A small
per-document "#metadata(none) " anchor - the same trick HTML
uses for an extra empty anchor per additional id on an element -
gives whole-document :doc: references something to link to even when
the target document has no sections, and covers section/signature
ids beyond the first, since Typst only allows one label per element.
Includes test coverage for basic cross-references, :ref: to named
targets, relative paths (including bare relative paths resolved from
the referring document's directory), nested documents, and edge
cases such as documents without sections and confval-style targets.
Summary by CodeRabbit
Release Notes
Bug Fixes
:doc:and:ref:role handling for internal and external linkingTests