Skip to content

Commit aa5a3f7

Browse files
committed
refactor: Use package relative filepath if filepath is not relative
Discussion mkdocstrings#622: mkdocstrings/mkdocstrings#622
1 parent 67df10c commit aa5a3f7

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,28 @@
9898
{% if config.show_source %}
9999
{% if config.merge_init_into_class %}
100100
{% if "__init__" in class.all_members and class.all_members["__init__"].source %}
101-
<details class="quote">
102-
<summary>Source code in <code>{{ class.relative_filepath }}</code></summary>
103-
{{ class.all_members["__init__"].source|highlight(language="python", linestart=class.all_members["__init__"].lineno, linenums=True) }}
104-
</details>
101+
{% with init = class.all_members["__init__"] %}
102+
<details class="quote">
103+
<summary>Source code in <code>
104+
{%- if init.relative_filepath.is_absolute() -%}
105+
{{ init.relative_package_filepath }}
106+
{%- else -%}
107+
{{ init.relative_filepath }}
108+
{%- endif -%}
109+
</code></summary>
110+
{{ init.source|highlight(language="python", linestart=init.lineno, linenums=True) }}
111+
</details>
112+
{% endwith %}
105113
{% endif %}
106114
{% elif class.source %}
107115
<details class="quote">
108-
<summary>Source code in <code>{{ class.relative_filepath }}</code></summary>
116+
<summary>Source code in <code>
117+
{%- if class.relative_filepath.is_absolute() -%}
118+
{{ class.relative_package_filepath }}
119+
{%- else -%}
120+
{{ class.relative_filepath }}
121+
{%- endif -%}
122+
</code></summary>
109123
{{ class.source|highlight(language="python", linestart=class.lineno, linenums=True) }}
110124
</details>
111125
{% endif %}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@
7474
{% block source scoped %}
7575
{% if config.show_source and function.source %}
7676
<details class="quote">
77-
<summary>{{ lang.t("Source code in") }} <code>{{ function.relative_filepath }}</code></summary>
77+
<summary>{{ lang.t("Source code in") }} <code>
78+
{%- if function.relative_filepath.is_absolute() -%}
79+
{{ function.relative_package_filepath }}
80+
{%- else -%}
81+
{{ function.relative_filepath }}
82+
{%- endif -%}
83+
</code></summary>
7884
{{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
7985
</details>
8086
{% endif %}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy