You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The relative-crossref syntax lets you reference the current object or its parent by prefixing a crossref identifier with dots. For example, to cross-reference the current object's `name` member, you can write `[link to name attribute][.name]`. The "current object" is the object containing the docstring being rendered.
With scoped cross-references, you can write identifiers as if you wanted to access them from the current object's scope. The scoping rules do not exactly match Python's: you can reference members and siblings too, without prefixing with `self.` or `cls.`.
442
+
443
+
The following order is applied when resolving a name in a given scope:
444
+
445
+
1. member of the current object
446
+
2. parent class
447
+
3. repeat 1-2 within parent's scope
448
+
449
+
In practice, it means that the name is first looked up in members, then it is compared against the parent name (only if it's a class), then it is looked up in siblings. It continues climbing up the object tree until there's no parent, in which case it raises a name resolution error.
450
+
451
+
Cross-referencing an imported object will directly link to this object if the objects inventory of the project it comes from was [loaded][import]. You won't be able to cross-reference it within your own documentation with scoped references, if you happen to be rendering this external object too. In that case, you can use an absolute reference or a [relative][relative_crossrefs] one instead.
452
+
453
+
Another limitation is that you won't be able to reference an external package if its name can be resolved in the current object's scope.
Copy file name to clipboardExpand all lines: src/mkdocstrings_handlers/python/handler.py
+4
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,8 @@ class PythonHandler(BaseHandler):
85
85
"separate_signature": False,
86
86
"line_length": 60,
87
87
"merge_init_into_class": False,
88
+
"relative_crossrefs": False,
89
+
"scoped_crossrefs": False,
88
90
"show_docstring_attributes": True,
89
91
"show_docstring_functions": True,
90
92
"show_docstring_classes": True,
@@ -168,6 +170,8 @@ class PythonHandler(BaseHandler):
168
170
docstring_options (dict): The options for the docstring parser. See [docstring parsers](https://mkdocstrings.github.io/griffe/reference/docstrings/) and their options in Griffe docs.
169
171
docstring_section_style (str): The style used to render docstring sections. Options: `table`, `list`, `spacy`. Default: `"table"`.
170
172
merge_init_into_class (bool): Whether to merge the `__init__` method into the class' signature and docstring. Default: `False`.
173
+
relative_crossrefs (bool): Whether to enable the relative crossref syntax. Default: `False`.
174
+
scoped_crossrefs (bool): Whether to enable the scoped crossref ability. Default: `False`.
171
175
show_if_no_docstring (bool): Show the object heading even if it has no docstring or children with docstrings. Default: `False`.
172
176
show_docstring_attributes (bool): Whether to display the "Attributes" section in the object's docstring. Default: `True`.
173
177
show_docstring_functions (bool): Whether to display the "Functions" or "Methods" sections in the object's docstring. Default: `True`.
0 commit comments