Skip to content

Commit 97ce941

Browse files
committed
Revise cross-referencing guide
1 parent cf85a4b commit 97ce941

1 file changed

Lines changed: 115 additions & 28 deletions

File tree

user_guide/12-cross-referencing.qmd

Lines changed: 115 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,36 @@ tags: [Content, Configuration]
77

88
# Cross-Referencing
99

10-
Great Docs provides a linking system called GDLS (Great Docs Linking System) that automatically creates clickable navigation between your API reference pages. GDLS operates at three levels, each adding a different kind of connectivity to your documentation.
10+
Documentation becomes much more useful when readers can follow connections between related items.
11+
Without links, someone reading the `encode()` page has no easy way to discover that `decode()`
12+
exists, or that a higher-level `Pipeline` class ties everything together. Cross-references turn
13+
isolated pages into a connected web.
1114

12-
The first level is the `%seealso` directive, which adds structured "See Also" sections that link related items together. The second level is inline interlinks, which let you create Markdown-style links to API symbols anywhere in your prose. The third level is code autolinks, which automatically turn inline code references like `` `MyClass` `` into clickable links when they match a documented symbol.
15+
Great Docs provides a linking system called GDLS (Great Docs Linking System) that automatically
16+
creates clickable navigation between your API reference pages. GDLS operates at three levels, each
17+
adding a different kind of connectivity to your documentation.
1318

14-
All three mechanisms resolve against the same `objects.json` inventory that Great Docs generates during the build. To preview which symbols are available for linking before you build, run:
19+
The first level is the `%seealso` directive, which adds structured "See Also" sections that link
20+
related items together. The second level is inline interlinks, which let you create Markdown-style
21+
links to API symbols anywhere in your prose. The third level is code autolinks, which automatically
22+
turn inline code references like `` `MyClass` `` into clickable links when they match a documented
23+
symbol.
24+
25+
All three mechanisms resolve against the same `objects.json` inventory that Great Docs generates
26+
during the build. To preview which symbols are available for linking before you build, run:
1527

1628
```bash
1729
great-docs scan
1830
```
1931

32+
This is useful for confirming the exact names you can reference in your docstrings.
33+
2034
## The `%seealso` Directive
2135

22-
The `%seealso` directive adds a "See Also" section to a reference page. Place it anywhere in a docstring with a comma-separated list of related names:
36+
The most common cross-referencing need is connecting items that serve complementary roles: an
37+
encoder and a decoder, a reader and a writer, or a class and its factory function. The `%seealso`
38+
directive handles this by adding a "See Also" section at the bottom of a reference page. Place it
39+
anywhere in a docstring with a comma-separated list of related names:
2340

2441
```python
2542
def encode(data: bytes, encoding: str = "utf-8") -> str:
@@ -30,7 +47,8 @@ def encode(data: bytes, encoding: str = "utf-8") -> str:
3047
...
3148
```
3249

33-
Great Docs strips the directive from the rendered output and generates a "See Also" section with clickable links at the bottom of the page.
50+
Great Docs strips the directive from the rendered output and generates a "See Also" section with
51+
clickable links at the bottom of the page.
3452

3553
Names can reference any exported symbol, including class methods using dotted notation:
3654

@@ -46,7 +64,9 @@ class Validator:
4664

4765
### Adding Descriptions
4866

49-
You can add a short description after each name, separated by a colon. When descriptions are present, the See Also section renders as a list with each link followed by its description. Without descriptions, the links appear as a compact comma-separated line.
67+
You can add a short description after each name, separated by a colon. When descriptions are
68+
present, the See Also section renders as a list with each link followed by its description. Without
69+
descriptions, the links appear as a compact comma-separated line.
5070

5171
```python
5272
def load(path: str) -> dict:
@@ -70,7 +90,10 @@ def transform(data: dict) -> dict:
7090

7191
### NumPy-style See Also Sections
7292

73-
If your docstrings use the NumPy docstring format, you can write a standard See Also section instead of (or in addition to) the `%seealso` directive. Great Docs recognizes this format, preserves the descriptions, and merges it with any `%seealso` entries on the same page. Duplicate references are deduplicated automatically.
93+
If your docstrings use the NumPy docstring format, you can write a standard See Also section instead
94+
of (or in addition to) the `%seealso` directive. Great Docs recognizes this format, preserves the
95+
descriptions, and merges it with any `%seealso` entries on the same page. Duplicate references are
96+
deduplicated automatically.
7497

7598
```python
7699
def connect(host: str, port: int = 5432):
@@ -91,14 +114,22 @@ def connect(host: str, port: int = 5432):
91114
...
92115
```
93116

117+
Both formats produce the same rendered output. If a page has both a `%seealso` directive and a NumPy
118+
See Also section, the entries are merged and any duplicates are removed.
119+
94120
## Inline Interlinks
95121

96-
You can create inline links to other API items anywhere in your docstring text using the interlinks syntax. This is especially useful in class hierarchies and overview docstrings where you want to point readers to related pages. There are several forms:
122+
Sometimes you need to mention another API item in the middle of a prose explanation rather than in a
123+
structured "See Also" section. Inline interlinks let you create Markdown-style links to API symbols
124+
anywhere in your docstring text. This is especially useful in class hierarchies and overview
125+
docstrings where you want to point readers to related pages. There are several forms:
97126

98-
- Write `` [](`~mypackage.MyClass`) `` to display just `MyClass`. The `~` prefix strips the package path and shows only the short name.
99-
- Write `` [](`mypackage.MyClass`) `` to display the full path `mypackage.MyClass`.
100-
- Write `` [see this class](`mypackage.MyClass`) `` to display `see this class` as the link text.
101-
- Write `` [see this class](`~mypackage.MyClass`) `` to also display `see this class`. When you supply custom link text in the brackets, it is always used as-is regardless of the `~` prefix.
127+
- write `` [](`~mypackage.MyClass`) `` to display just `MyClass`. The `~` prefix strips the package
128+
path and shows only the short name
129+
- write `` [](`mypackage.MyClass`) `` to display the full path `mypackage.MyClass`
130+
- write `` [see this class](`mypackage.MyClass`) `` to display `see this class` as the link text
131+
- write `` [see this class](`~mypackage.MyClass`) `` to also display `see this class`; when you
132+
supply custom link text in the brackets, it is always used as-is regardless of the `~` prefix
102133

103134
Here is an example showing interlinks in practice:
104135

@@ -117,11 +148,16 @@ class BaseStore:
117148
...
118149
```
119150

120-
In the rendered documentation, each interlinks reference becomes a clickable link pointing to the target's reference page. Interlinks work in any part of a docstring: the summary line, extended description, parameter descriptions, notes, or any other section.
151+
Interlinks work in any part of a docstring: the summary line, extended description, parameter
152+
descriptions, notes, or any other section. If a reference cannot be resolved (for example, a typo in
153+
the symbol name), the link text still renders but without a clickable link.
121154

122155
## Code Autolinks
123156

124-
Great Docs automatically converts inline code in docstrings into clickable links when the code matches a documented API symbol. No special syntax is needed; you use standard backtick code formatting and Great Docs does the rest:
157+
The first two levels (`%seealso` and interlinks) require you to opt in by writing specific syntax.
158+
Code autolinks take a different approach: they work automatically with no markup at all. When Great
159+
Docs encounters inline code in a docstring that matches a documented API symbol, it turns that code
160+
into a clickable link:
125161

126162
```python
127163
class Engine:
@@ -133,11 +169,13 @@ class Engine:
133169
...
134170
```
135171

136-
In the rendered output, `` `Pipeline` `` and `` `run_pipeline()` `` become clickable links to their respective reference pages.
172+
In the rendered output, `` `Pipeline` `` and `` `run_pipeline()` `` become clickable links to their
173+
respective reference pages.
137174

138175
### Shortening Prefixes
139176

140-
For qualified names, you can control the display text with `~~` prefixes. The double tilde strips everything before the last component of the dotted path:
177+
For qualified names, you can control the display text with `~~` prefixes. The double tilde strips
178+
everything before the last component of the dotted path:
141179

142180
| What you write | What renders | What it links to |
143181
|---|---|---|
@@ -147,11 +185,14 @@ For qualified names, you can control the display text with `~~` prefixes. The do
147185
| `` `~~mypackage.my_func()` `` | `my_func()` | my_func page |
148186
| `` `~~.mypackage.MyClass` `` | `.MyClass` | MyClass page |
149187

150-
If the name does not match any documented symbol (e.g., `` `~~unknown_func()` ``), it renders as plain code with no link.
188+
If the name does not match any documented symbol (e.g., `` `~~unknown_func()` ``), it renders as
189+
plain code with no link.
151190

152191
### What Gets Autolinked
153192

154-
Any inline code that looks like an identifier or dotted path is a candidate for autolinking. Parentheses at the end are allowed. Code that contains arguments, spaces, or operators is not linked.
193+
Any inline code that looks like an identifier or dotted path is a candidate for autolinking.
194+
Parentheses at the end are allowed. Code that contains arguments, spaces, or operators is not
195+
linked.
155196

156197
Examples that will be linked (if the name exists in the API):
157198

@@ -165,30 +206,76 @@ Examples that will not be linked:
165206
- `` `a + b` `` (contains operators)
166207
- `` `-MyClass` `` (starts with an operator)
167208

209+
When in doubt, write the name as you normally would in a docstring. If it resolves, it becomes a
210+
link; if not, it renders as plain code.
211+
212+
## Parentheses in Cross-References
213+
214+
The three cross-referencing levels handle parentheses differently, so it helps to know the rules:
215+
216+
**`%seealso`**: Write bare names without parentheses. Great Docs automatically appends `()` to
217+
functions and methods in the rendered "See Also" section based on each symbol's type. Writing
218+
`%seealso decode, MyClass` produces `decode()` and `MyClass` in the output, with the parentheses
219+
added only where appropriate.
220+
221+
**Inline interlinks**: The target inside backticks should be the qualified name without parentheses.
222+
Write `` [](`~mypackage.my_func`) ``, not `` [](`~mypackage.my_func()`) ``.
223+
224+
**Code autolinks**: Trailing `()` are optional and purely cosmetic. Both `` `my_func` `` and
225+
`` `my_func()` `` resolve to the same page. The parentheses are preserved in the display text but
226+
stripped during lookup. Use `()` when you want to signal to readers that something is callable:
227+
228+
```python
229+
class Pipeline:
230+
"""Chain multiple engines together.
231+
232+
Call `run()` to execute the pipeline, or inspect `config` for current settings.
233+
"""
234+
...
235+
```
236+
237+
In the rendered output, `run()` links to the `run` method page (with parentheses displayed) and
238+
`config` links to the `config` attribute page (without parentheses).
239+
168240
### Disabling Autolinks
169241

170-
To prevent a specific piece of inline code from being autolinked, add the `{.gd-no-link}` class after the backtick span:
242+
To prevent a specific piece of inline code from being autolinked, add the `{.gd-no-link}` class
243+
after the backtick span:
171244

172245
```markdown
173246
The `Config`{.gd-no-link} parameter is a plain dictionary, not the Config class.
174247
```
175248

176-
This is useful when a word happens to match a documented symbol but you are referring to something else in context.
249+
This is useful when a word happens to match a documented symbol but you are referring to something
250+
else in context. You only need this occasionally; most autolinks are helpful and should be left in
251+
place.
177252

178253
## Best Practices for Linking
179254

180-
Cross-references make documentation much more navigable, but a few guidelines help keep them useful rather than distracting.
255+
Cross-references make documentation much more navigable, but a few guidelines help keep them useful
256+
rather than distracting.
181257

182-
Use `%seealso` to connect items that serve complementary roles. If `encode()` and `decode()` are a natural pair, linking them together helps readers discover both. For larger groupings, a brief description after each name (using the colon syntax) gives context about why the link is relevant.
258+
Use `%seealso` to connect items that serve complementary roles. If `encode()` and `decode()` are a
259+
natural pair, linking them together helps readers discover both. For larger groupings, a brief
260+
description after each name (using the colon syntax) gives context about why the link is relevant.
183261

184-
Use inline interlinks when you mention another symbol in the middle of a prose explanation. This keeps reading flow natural while still giving readers a path to the referenced page. The shortened form (with `~`) is usually the best choice because fully qualified paths can be long and interrupt the sentence visually.
262+
Use inline interlinks when you mention another symbol in the middle of a prose explanation. This
263+
keeps reading flow natural while still giving readers a path to the referenced page. The shortened
264+
form (with `~`) is usually the best choice because fully qualified paths can be long and interrupt
265+
the sentence visually.
185266

186-
Code autolinks require no effort on your part, since they happen automatically. But be aware that common words like `Config` or `Data` might match a symbol unexpectedly. If you notice unwanted links in the rendered output, add `{.gd-no-link}` to the specific code span.
267+
Code autolinks require no effort on your part, since they happen automatically. But be aware that
268+
common words like `Config` or `Data` might match a symbol unexpectedly. If you notice unwanted links
269+
in the rendered output, add `{.gd-no-link}` to the specific code span.
187270

188271
## Next Steps
189272

190-
Cross-references turn a collection of standalone reference pages into a connected web of documentation. Use `%seealso` for structured navigation, interlinks for inline mentions, and let code autolinks handle the rest automatically.
273+
Cross-references turn a collection of standalone reference pages into a connected web of
274+
documentation. Use `%seealso` for structured navigation, interlinks for inline mentions, and let
275+
code autolinks handle the rest automatically.
191276

192-
- [API Documentation](api-documentation.qmd) covers how discovery and organization work
193-
- [Configuration](configuration.qmd) covers the functional settings in `great-docs.yml`
194-
- [Theming & Appearance](theming.qmd) covers visual customization options
277+
- [Writing Docstrings](writing-docstrings.qmd) covers how to write effective docstrings that work
278+
well with cross-referencing
279+
- [API Documentation](api-documentation.qmd) covers how API discovery and page organization work
280+
- [User Guides](user-guides.qmd) explains how to link from User Guide pages to API reference pages
281+
- [Linting](linting.qmd) can catch broken cross-references during the build

0 commit comments

Comments
 (0)