From 3ed2f07848da15d9057c536cdd544732c574ba17 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Sun, 4 Feb 2024 13:49:01 +0100 Subject: [PATCH 1/3] Add `show_labels` config option --- docs/usage/configuration/members.md | 46 +++++++++++++++++++ src/mkdocstrings_handlers/python/handler.py | 2 + .../templates/material/_base/labels.html | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/docs/usage/configuration/members.md b/docs/usage/configuration/members.md index f558040f..73354a6f 100644 --- a/docs/usage/configuration/members.md +++ b/docs/usage/configuration/members.md @@ -643,3 +643,49 @@ plugins: //// /// + +## `show_labels` + +- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** + + +Whether to show labels of the members. Defaults to `True`. + +```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 | Show +

+ some_attr: int + + instance-attribute + +

+//// + +//// tab | Don't show +

+ some_attr: int +

+//// +/// diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 7ffdaf6b..c5217e98 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -106,6 +106,7 @@ class PythonHandler(BaseHandler): "preload_modules": None, "allow_inspection": True, "summary": False, + "show_labels": True, "unwrap_annotated": False, } """Default handler configuration. @@ -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"`. diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/labels.html b/src/mkdocstrings_handlers/python/templates/material/_base/labels.html index 0c84067a..a35bffbb 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/labels.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/labels.html @@ -1,4 +1,4 @@ -{% if labels %} +{% if config.show_labels and labels %} {{ log.debug("Rendering labels") }} {% for label in labels|sort %} From e5b46a68583bb02529b73c385d573e5c16222e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 5 Feb 2024 13:43:19 +0100 Subject: [PATCH 2/3] fixup! Add `show_labels` config option --- docs/usage/configuration/members.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/usage/configuration/members.md b/docs/usage/configuration/members.md index 73354a6f..988b63bb 100644 --- a/docs/usage/configuration/members.md +++ b/docs/usage/configuration/members.md @@ -674,18 +674,18 @@ class SomeClass: /// admonition | Preview type: preview -//// tab | Show -

- some_attr: int - - instance-attribute - -

+//// tab | With labels + + some_attr: + int + +instance-attribute //// -//// tab | Don't show -

- some_attr: int -

+//// tab | Without labels + + some_attr: + int + //// /// From 295005c55fee8e417b24bbb5ee8b13279ab05aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 5 Feb 2024 13:44:26 +0100 Subject: [PATCH 3/3] fixup! Add `show_labels` config option --- docs/usage/configuration/members.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/configuration/members.md b/docs/usage/configuration/members.md index 988b63bb..1e5ff771 100644 --- a/docs/usage/configuration/members.md +++ b/docs/usage/configuration/members.md @@ -649,7 +649,7 @@ plugins: - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** -Whether to show labels of the members. Defaults to `True`. +Whether to show labels of the members. ```yaml title="in mkdocs.yml (global configuration)" plugins: