From c6f36c0c9e5141800f8c5c988c9b67720fccccb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 24 Aug 2023 21:18:56 +0200 Subject: [PATCH 1/5] fix: Prevent whitespace removal before highlight filter --- .../python/templates/material/_base/attribute.html | 2 +- .../python/templates/material/_base/class.html | 12 ++++++------ .../python/templates/material/_base/function.html | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html index 404532c6..e9aabce1 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html @@ -25,7 +25,7 @@ {% if config.separate_signature %} {% if show_full_path %}{{ attribute.path }}{% else %}{{ attribute.name }}{% endif %} {% else %} - {% filter highlight(language="python", inline=True) %} + {%+ filter highlight(language="python", inline=True) %} {% if show_full_path %}{{ attribute.path }}{% else %}{{ attribute.name }}{% endif %} {% if attribute.annotation %}: {{ attribute.annotation }}{% endif %} {% if attribute.value %} = {{ attribute.value }}{% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/class.html b/src/mkdocstrings_handlers/python/templates/material/_base/class.html index f137686f..695cda05 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/class.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/class.html @@ -24,13 +24,13 @@ {% block heading scoped %} {% if config.separate_signature %} {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %} - {% elif config.merge_init_into_class and "__init__" in class.members -%} - {%- with function = class.members["__init__"] -%} - {%- filter highlight(language="python", inline=True) -%} + {% elif config.merge_init_into_class and "__init__" in class.members %} + {% with function = class.members["__init__"] %} + {%+ filter highlight(language="python", inline=True) %} {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %} - {%- include "signature.html" with context -%} - {%- endfilter -%} - {%- endwith -%} + {% include "signature.html" with context %} + {% endfilter %} + {% endwith %} {% else %} {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %} {% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/function.html b/src/mkdocstrings_handlers/python/templates/material/_base/function.html index bccafc0c..3b8093d7 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/function.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/function.html @@ -27,7 +27,7 @@ {% if config.separate_signature %} {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %} {% else %} - {% filter highlight(language="python", inline=True) %} + {%+ filter highlight(language="python", inline=True) %} {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %} {% include "signature.html" with context %} {% endfilter %} From 38b317f4fc74b583a4788721a5559c51a5a47d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 24 Aug 2023 21:20:59 +0200 Subject: [PATCH 2/5] refactor: Sync templates with insiders, remove useless lines --- .../templates/material/_base/attribute.html | 10 ++++----- .../templates/material/_base/class.html | 17 +++++++------- .../templates/material/_base/function.html | 7 +++--- .../templates/material/_base/module.html | 22 +++++++++---------- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html index e9aabce1..baaa5378 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html @@ -13,6 +13,8 @@ {% set show_full_path = config.show_object_full_path %} {% endif %} + {% set attribute_name = attribute.path if show_full_path else attribute.name %} + {% if not root or config.show_root_heading %} {% filter heading(heading_level, @@ -23,11 +25,10 @@ {% block heading scoped %} {% if config.separate_signature %} - {% if show_full_path %}{{ attribute.path }}{% else %}{{ attribute.name }}{% endif %} + {{ attribute_name }} {% else %} {%+ filter highlight(language="python", inline=True) %} - {% if show_full_path %}{{ attribute.path }}{% else %}{{ attribute.name }}{% endif %} - {% if attribute.annotation %}: {{ attribute.annotation }}{% endif %} + {{ attribute_name }}{% if attribute.annotation %}: {{ attribute.annotation }}{% endif %} {% if attribute.value %} = {{ attribute.value }}{% endif %} {% endfilter %} {% endif %} @@ -45,8 +46,7 @@ {% if config.separate_signature %} {% filter highlight(language="python", inline=False) %} {% filter format_code(config.line_length) %} - {{ attribute.name }} - {% if attribute.annotation %}: {{ attribute.annotation|safe }}{% endif %} + {{ attribute.name }}{% if attribute.annotation %}: {{ attribute.annotation|safe }}{% endif %} {% if attribute.value %} = {{ attribute.value|safe }}{% endif %} {% endfilter %} {% endfilter %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/class.html b/src/mkdocstrings_handlers/python/templates/material/_base/class.html index 695cda05..1e1c0516 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/class.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/class.html @@ -13,6 +13,8 @@ {% set show_full_path = config.show_object_full_path %} {% endif %} + {% set class_name = class.path if show_full_path else class.name %} + {% if not root or config.show_root_heading %} {% filter heading(heading_level, @@ -23,16 +25,15 @@ {% block heading scoped %} {% if config.separate_signature %} - {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %} + {{ class_name }} {% elif config.merge_init_into_class and "__init__" in class.members %} {% with function = class.members["__init__"] %} {%+ filter highlight(language="python", inline=True) %} - {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %} - {% include "signature.html" with context %} + {{ class_name }}{% include "signature.html" with context %} {% endfilter %} {% endwith %} {% else %} - {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %} + {{ class_name }} {% endif %} {% endblock heading %} @@ -112,11 +113,9 @@ {% endblock source %} {% block children scoped %} - {% with obj = class %} - {% set root = False %} - {% set heading_level = heading_level + 1 %} - {% include "children.html" with context %} - {% endwith %} + {% set root = False %} + {% set heading_level = heading_level + 1 %} + {% include "children.html" with context %} {% endblock children %} {% endblock contents %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/function.html b/src/mkdocstrings_handlers/python/templates/material/_base/function.html index 3b8093d7..1eb1efac 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/function.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/function.html @@ -15,6 +15,8 @@ {% set show_full_path = config.show_object_full_path %} {% endif %} + {% set function_name = function.path if show_full_path else function.name %} + {% if not root or config.show_root_heading %} {% filter heading(heading_level, @@ -25,11 +27,10 @@ {% block heading scoped %} {% if config.separate_signature %} - {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %} + {{ function_name }} {% else %} {%+ filter highlight(language="python", inline=True) %} - {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %} - {% include "signature.html" with context %} + {{ function_name }}{% include "signature.html" with context %} {% endfilter %} {% endif %} {% endblock heading %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/module.html b/src/mkdocstrings_handlers/python/templates/material/_base/module.html index ce62f8e7..ae0154c3 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/module.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/module.html @@ -13,6 +13,8 @@ {% set show_full_path = config.show_object_full_path %} {% endif %} + {% set module_name = module.path if show_full_path else module.name %} + {% if not root or config.show_root_heading %} {% filter heading(heading_level, @@ -22,13 +24,11 @@ toc_label=module.name) %} {% block heading scoped %} - {% with module_name = module.path if show_full_path else module.name %} - {% if config.separate_signature %} - {{ module_name }} - {% else %} - {{ module_name }} - {% endif %} - {% endwith %} + {% if config.separate_signature %} + {{ module_name }} + {% else %} + {{ module_name }} + {% endif %} {% endblock heading %} {% block labels scoped %} @@ -60,11 +60,9 @@ {% endblock docstring %} {% block children scoped %} - {% with obj = module %} - {% set root = False %} - {% set heading_level = heading_level + 1 %} - {% include "children.html" with context %} - {% endwith %} + {% set root = False %} + {% set heading_level = heading_level + 1 %} + {% include "children.html" with context %} {% endblock children %} {% endblock contents %} From 9aa758bcc42dfcf7c416d87b8f7cd407b7fdf148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 24 Aug 2023 21:21:33 +0200 Subject: [PATCH 3/5] refactor: Never show full object path in ToC entry --- .../python/templates/material/_base/attribute.html | 2 +- .../python/templates/material/_base/class.html | 2 +- .../python/templates/material/_base/function.html | 2 +- .../python/templates/material/_base/module.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html index baaa5378..c9fa126f 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html @@ -58,7 +58,7 @@ {% filter heading(heading_level, role="data" if attribute.parent.kind.value == "module" else "attr", id=html_id, - toc_label=attribute.path if config.show_root_full_path else attribute.name, + toc_label=attribute.name, hidden=True) %} {% endfilter %} {% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/class.html b/src/mkdocstrings_handlers/python/templates/material/_base/class.html index 1e1c0516..186de8ff 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/class.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/class.html @@ -62,7 +62,7 @@ {% filter heading(heading_level, role="class", id=html_id, - toc_label=class.path if config.show_root_full_path else class.name, + toc_label=class.name, hidden=True) %} {% endfilter %} {% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/function.html b/src/mkdocstrings_handlers/python/templates/material/_base/function.html index 1eb1efac..c12bb1c3 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/function.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/function.html @@ -56,7 +56,7 @@ {% filter heading(heading_level, role="function", id=html_id, - toc_label=function.path if config.show_root_full_path else function.name, + toc_label=function.name, hidden=True) %} {% endfilter %} {% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/module.html b/src/mkdocstrings_handlers/python/templates/material/_base/module.html index ae0154c3..dc44142b 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/module.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/module.html @@ -44,7 +44,7 @@ {% filter heading(heading_level, role="module", id=html_id, - toc_label=module.path if config.show_root_full_path else module.name, + toc_label=module.name, hidden=True) %} {% endfilter %} {% endif %} From beeebffa36288d1f71d122f78ecd9064b41a75d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 25 Aug 2023 15:54:17 +0200 Subject: [PATCH 4/5] fix: Regression in children template: fix condition for when members are specified Issue #100: https://github.com/mkdocstrings/python/issues/100 --- .../python/templates/material/_base/children.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/children.html b/src/mkdocstrings_handlers/python/templates/material/_base/children.html index 19b9c676..25534f70 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/children.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/children.html @@ -31,7 +31,7 @@ {% endif %} {% with heading_level = heading_level + extra_level %} {% for attribute in attributes|order_members(config.members_order, members_list) %} - {% if members_list is none and attribute.is_public(check_name=False) %} + {% if members_list is not none or attribute.is_public(check_name=False) %} {% include attribute|get_template with context %} {% endif %} {% endfor %} @@ -51,7 +51,7 @@ {% endif %} {% with heading_level = heading_level + extra_level %} {% for class in classes|order_members(config.members_order, members_list) %} - {% if members_list is none and class.is_public(check_name=False) %} + {% if members_list is not none or class.is_public(check_name=False) %} {% include class|get_template with context %} {% endif %} {% endfor %} @@ -72,7 +72,7 @@ {% with heading_level = heading_level + extra_level %} {% for function in functions|order_members(config.members_order, members_list) %} {% if not (obj.kind.value == "class" and function.name == "__init__" and config.merge_init_into_class) %} - {% if members_list is none and function.is_public(check_name=False) %} + {% if members_list is not none or function.is_public(check_name=False) %} {% include function|get_template with context %} {% endif %} {% endif %} @@ -94,7 +94,7 @@ {% endif %} {% with heading_level = heading_level + extra_level %} {% for module in modules|order_members(config.members_order.alphabetical, members_list) %} - {% if members_list is none and module.is_public(check_name=False) %} + {% if members_list is not none or module.is_public(check_name=False) %} {% include module|get_template with context %} {% endif %} {% endfor %} @@ -119,7 +119,7 @@ {% if not (obj.is_class and child.name == "__init__" and config.merge_init_into_class) %} - {% if members_list is none and child.is_public(check_name=False) %} + {% if members_list is not none or child.is_public(check_name=False) %} {% if child.is_attribute %} {% with attribute = child %} {% include attribute|get_template with context %} From d56ebcc2b92e3b1513300977600c197edef31989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 25 Aug 2023 15:54:49 +0200 Subject: [PATCH 5/5] chore: Prepare release 1.5.2 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2096e6c..207a8803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.5.2](https://github.com/mkdocstrings/python/releases/tag/1.5.2) - 2023-08-25 + +[Compare with 1.5.1](https://github.com/mkdocstrings/python/compare/1.5.1...1.5.2) + +### Bug Fixes + +- Regression in children template: fix condition for when members are specified ([beeebff](https://github.com/mkdocstrings/python/commit/beeebffa36288d1f71d122f78ecd9064b41a75d0) by Timothée Mazzucotelli). [Issue #100](https://github.com/mkdocstrings/python/issues/100) +- Prevent whitespace removal before highlight filter ([c6f36c0](https://github.com/mkdocstrings/python/commit/c6f36c0c9e5141800f8c5c988c9b67720fccccb8) by Timothée Mazzucotelli). + +### Code Refactoring + +- Never show full object path in ToC entry ([9aa758b](https://github.com/mkdocstrings/python/commit/9aa758bcc42dfcf7c416d87b8f7cd407b7fdf148) by Timothée Mazzucotelli). +- Sync templates with insiders, remove useless lines ([38b317f](https://github.com/mkdocstrings/python/commit/38b317f4fc74b583a4788721a5559c51a5a47d86) by Timothée Mazzucotelli). + ## [1.5.1](https://github.com/mkdocstrings/python/releases/tag/1.5.1) - 2023-08-24 [Compare with 1.5.0](https://github.com/mkdocstrings/python/compare/1.5.0...1.5.1)