Skip to content

Commit

Permalink
feat: Add show_labels option to show/hide labels
Browse files Browse the repository at this point in the history
Issue #120: #120
PR #130: #130
  • Loading branch information
Viicos authored Feb 5, 2024
1 parent 8e86778 commit eaf9b82
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
46 changes: 46 additions & 0 deletions docs/usage/configuration/members.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,49 @@ plugins:
</ul>
////
///
## `show_labels`
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
Whether to show labels of the members.
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
show_labels: true
```

```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
show_labels: false
```

```python title="package/module.py"
class SomeClass:
some_attr: int
```

/// admonition | Preview
type: preview

//// tab | With labels
<code class="highlight language-python">
<span class="n">some_attr</span><span class="p">:</span>
<span class="nb">int</span>
</code>
<small><code>instance-attribute</code></small>
////

//// tab | Without labels
<code class="highlight language-python">
<span class="n">some_attr</span><span class="p">:</span>
<span class="nb">int</span>
</code>
////
///
2 changes: 2 additions & 0 deletions src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class PythonHandler(BaseHandler):
"preload_modules": None,
"allow_inspection": True,
"summary": False,
"show_labels": True,
"unwrap_annotated": False,
}
"""Default handler configuration.
Expand Down Expand Up @@ -154,6 +155,7 @@ class PythonHandler(BaseHandler):
group_by_category (bool): Group the object's children by categories: attributes, classes, functions, and modules. Default: `True`.
show_submodules (bool): When rendering a module, show its submodules recursively. Default: `False`.
summary (bool | dict[str, bool]): Whether to render summaries of modules, classes, functions (methods) and attributes.
show_labels (bool): Whether to show labels of the members. Default: `True`.
Attributes: Docstrings options:
docstring_style (str): The docstring style to use: `google`, `numpy`, `sphinx`, or `None`. Default: `"google"`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if labels %}
{% if config.show_labels and labels %}
{{ log.debug("Rendering labels") }}
<span class="doc doc-labels">
{% for label in labels|sort %}
Expand Down

0 comments on commit eaf9b82

Please sign in to comment.