8000 feat: Add `show_labels` option to show/hide labels · mkdocstrings/python@eaf9b82 · GitHub
[go: up one dir, main page]

Skip to content

Commit eaf9b82

Browse files
authored
feat: Add show_labels option to show/hide labels
Issue #120: #120 PR #130: #130
1 parent 8e86778 commit eaf9b82

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

docs/usage/configuration/members.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,49 @@ plugins:
643643
</ul>
644644
////
645645
///
646+
647+
## `show_labels`
648+
649+
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
650+
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
651+
652+
Whether to show labels of the members.
653+
654+
```yaml title="in mkdocs.yml (global configuration)"
655+
plugins:
656+
- mkdocstrings:
657+
handlers:
658+
python:
659+
options:
660+
show_labels: true
661+
```
662+
663+
```md title="or in docs/some_page.md (local configuration)"
664+
::: package.module
665+
options:
666+
show_labels: false
667+
```
668+
669+
```python title="package/module.py"
670+
class SomeClass:
671+
some_attr: int
672+
```
673+
674+
/// admonition | Preview
675+
type: preview
676+
677+
//// tab | With labels
678+
<code class="highlight language-python">
679+
<span class="n">some_attr</span><span class="p">:</span>
680+
<span class="nb">int</span>
681+
</code>
682+
<small><code>instance-attribute</code></small>
683+
////
684+
685+
//// tab | Without labels
686+
<code class="highlight language-python">
687+
<span class="n">some_attr</span><span class="p">:</span>
688+
<span class="nb">int</span>
689+
</code>
690+
////
691+
///

src/mkdocstrings_handlers/python/handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class PythonHandler(BaseHandler):
106106
"preload_modules": None,
107107
"allow_inspection": True,
108108
"summary": False,
109+
"show_labels": True,
109110
"unwrap_annotated": False,
110111
}
111112
"""Default handler configuration.
@@ -154,6 +155,7 @@ class PythonHandler(BaseHandler):
154155
group_by_category (bool): Group the object's children by categories: attributes, classes, functions, and modules. Default: `True`.
155156
show_submodules (bool): When rendering a module, show its submodules recursively. Default: `False`.
156157
summary (bool | dict[str, bool]): Whether to render summaries of modules, classes, functions (methods) and attributes.
158+
show_labels (bool): Whether to show labels of the members. Default: `True`.
157159
158160
Attributes: Docstrings options:
159161
docstring_style (str): The docstring style to use: `google`, `numpy`, `sphinx`, or `None`. Default: `"google"`.

src/mkdocstrings_handlers/python/templates/material/_base/labels.html

Lines change 5E1D d: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% if labels %}
1+
{% if config.show_labels and labels %}
22
{{ log.debug("Rendering labels") }}
33
<span class="doc doc-labels">
44
{% for label in labels|sort %}

0 commit comments

Comments
 (0)
0