88
99.. versionadded :: 0.5
1010
11- This extension can generate automatic links to the documentation of objects in
12- other projects.
13-
14- Usage is simple: whenever Sphinx encounters a cross-reference that has no
15- matching target in the current documentation set, it looks for targets in the
16- documentation sets configured in :confval: `intersphinx_mapping `. A reference
17- like ``:py:class:`zipfile.ZipFile` `` can then link to the Python documentation
11+ This extension can generate links to the documentation of objects in external
12+ projects, either explicitly through the :rst:role: `external ` role, or as a
13+ fallback resolution for any other cross-reference.
14+
15+ Usage for fallback resolution is simple: whenever Sphinx encounters a
16+ cross-reference that has no matching target in the current documentation set,
17+ it looks for targets in the external documentation sets configured in
18+ :confval: `intersphinx_mapping `. A reference like
19+ ``:py:class:`zipfile.ZipFile` `` can then link to the Python documentation
1820for the ZipFile class, without you having to specify where it is located
1921exactly.
2022
21- When using the "new" format (see below), you can even force lookup in a foreign
22- set by prefixing the link target appropriately. A link like ``:ref:`comparison
23- manual <python:comparisons>` `` will then link to the label "comparisons" in the
24- doc set "python", if it exists.
23+ When using the :rst:role: `external ` role, you can force lookup to any external
24+ projects, and optionally to a specific external project.
25+ A link like ``:external:ref:`comparison manual <comparisons>` `` will then link
26+ to the label "comparisons" in whichever configured external project, if it
27+ exists,
28+ and a link like ``:external:python+ref:`comparison manual <comparisons>` `` will
29+ link to the label "comparisons" only in the doc set "python", if it exists.
2530
2631Behind the scenes, this works as follows:
2732
@@ -30,8 +35,8 @@ Behind the scenes, this works as follows:
3035
3136* Projects using the Intersphinx extension can specify the location of such
3237 mapping files in the :confval: `intersphinx_mapping ` config value. The mapping
33- will then be used to resolve otherwise missing references to objects into
34- links to the other documentation.
38+ will then be used to resolve both :rst:role: ` external ` references, and also
39+ otherwise missing references to objects into links to the other documentation.
3540
3641* By default, the mapping file is assumed to be at the same location as the rest
3742 of the documentation; however, the location of the mapping file can also be
@@ -79,10 +84,10 @@ linking:
7984 at the same location as the base URI) or another local file path or a full
8085 HTTP URI to an inventory file.
8186
82- The unique identifier can be used to prefix cross-reference targets , so that
87+ The unique identifier can be used in the :rst:role: ` external ` role , so that
8388 it is clear which intersphinx set the target belongs to. A link like
84- ``: ref:`comparison manual <python: comparisons>` `` will link to the label
85- "comparisons" in the doc set "python", if it exists.
89+ ``external:python+ ref:`comparison manual <comparisons>` `` will link to the
90+ label "comparisons" in the doc set "python", if it exists.
8691
8792 **Example **
8893
@@ -162,21 +167,50 @@ linking:
162167
163168 The default value is an empty list.
164169
165- When a cross-reference without an explicit inventory specification is being
166- resolved by intersphinx, skip resolution if it matches one of the
167- specifications in this list.
170+ When a non- :rst:role: ` external ` cross-reference is being resolved by
171+ intersphinx, skip resolution if it matches one of the specifications in this
172+ list.
168173
169174 For example, with ``intersphinx_disabled_reftypes = ['std:doc'] ``
170175 a cross-reference ``:doc:`installation` `` will not be attempted to be
171- resolved by intersphinx, but ``:doc:` otherbook: installation` `` will be
172- attempted to be resolved in the inventory named ``otherbook `` in
176+ resolved by intersphinx, but ``:external: otherbook+doc:` installation` `` will
177+ be attempted to be resolved in the inventory named ``otherbook `` in
173178 :confval: `intersphinx_mapping `.
174179 At the same time, all cross-references generated in, e.g., Python,
175180 declarations will still be attempted to be resolved by intersphinx.
176181
177- If ``* `` is in the list of domains, then no references without an explicit
178- inventory will be resolved by intersphinx.
182+ If ``* `` is in the list of domains, then no non-:rst:role: `external `
183+ references will be resolved by intersphinx.
184+
185+ Explicitly Reference External Objects
186+ -------------------------------------
187+
188+ The Intersphinx extension provides the following role.
189+
190+ .. rst :role :: external
191+
192+ .. versionadded :: 4.4
193+
194+ Use Intersphinx to perform lookup only in external projects, and not the
195+ current project. Intersphinx still needs to know the type of object you
196+ would like to find, so the general form of this role is to write the
197+ cross-refererence as if the object is in the current project, but then prefix
198+ it with ``:external ``.
199+ The two forms are then
200+
201+ - ``:external:domain:reftype:`target` ``,
202+ e.g., ``:external:py:class:`zipfile.ZipFile` ``, or
203+ - ``:external:reftype:`target` ``,
204+ e.g., ``:external:doc:`installation` ``.
205+
206+ If you would like to constrain the lookup to a specific external project,
207+ then the key of the project, as specified in :confval: `intersphinx_mapping `,
208+ is added as well to get the two forms
179209
210+ - ``:external:invname+domain:reftype:`target` ``,
211+ e.g., ``:external:python+py:class:`zipfile.ZipFile` ``, or
212+ - ``:external:invname+reftype:`target` ``,
213+ e.g., ``:external:python+doc:`installation` ``.
180214
181215Showing all links of an Intersphinx mapping file
182216------------------------------------------------
0 commit comments