Skip to content

Commit

Permalink
refactor: Use new autorefs syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Aug 30, 2024
1 parent 2299ab5 commit 5705c00
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 29 deletions.
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ hide:
---

--8<-- "README.md"

## License

Link to [license][].
12 changes: 6 additions & 6 deletions docs/usage/configuration/docstrings.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ In that case, the Spacy tables can help.

**Type** | **Name** | **Description** | **Default**
---------- | ----------- | ------------------------ | -----------
<code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="int">int</span> \| <span data-autorefs-optional="float">float</span>]</code> | `gravity_forces` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | *required*
<code><span data-autorefs-optional="VacuumType">VacuumType</span> \| <span data-autorefs-optional="typing.Literal">Literal</span>["regular"]</code> | `vacuum_type` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | `VacuumType.PLASMA`
<code><autoref identifier="list" optional>list</autoref>[<autoref identifier="int" optional>int</autoref> \| <autoref identifier="float" optional>float</autoref>]</code> | `gravity_forces` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | *required*
<code><autoref identifier="VacuumType" optional>VacuumType</autoref> \| <autoref identifier="typing.Literal" optional>Literal</autoref>["regular"]</code> | `vacuum_type` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | `VacuumType.PLASMA`
////

//// tab | List
Expand All @@ -222,8 +222,8 @@ Lists work well whatever the length of names, type annotations, descriptions, et

**Other Parameters:**

- `gravity_forces` (<code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="int">int</span> \| <span data-autorefs-optional="float">float</span>]</code>) &mdash; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- `vacuum_type` (<code><span data-autorefs-optional="VacuumType">VacuumType</span> \| <span data-autorefs-optional="typing.Literal">Literal</span>["regular"]</code>) &mdash; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- `gravity_forces` (<code><autoref identifier="list" optional>list</autoref>[<autoref identifier="int" optional>int</autoref> \| <autoref identifier="float" optional>float</autoref>]</code>) &mdash; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- `vacuum_type` (<code><autoref identifier="VacuumType" optional>VacuumType</autoref> \| <autoref identifier="typing.Literal" optional>Literal</autoref>["regular"]</code>) &mdash; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
////

//// tab | Spacy
Expand All @@ -241,8 +241,8 @@ by reserving more horizontal space on the second column.

**Name** | **Description**
----------- | ---------------
`gravity_forces` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>**TYPE:** <code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="int">int</span> \| <span data-autorefs-optional="float">float</span>]</code> <span style="float: right;"><b>DEFAULT:</b> <i>required</i></span>
`vacuum_type` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>**TYPE:**<code><span data-autorefs-optional="VacuumType">VacuumType</span> \| <span data-autorefs-optional="typing.Literal">Literal</span>["regular"]</code> <span style="float: right;"><b>DEFAULT:</b> <code>VacuumType.PLASMA</code></span>
`gravity_forces` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>**TYPE:** <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="int" optional>int</autoref> \| <autoref identifier="float" optional>float</autoref>]</code> <span style="float: right;"><b>DEFAULT:</b> <i>required</i></span>
`vacuum_type` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>**TYPE:**<code><autoref identifier="VacuumType" optional>VacuumType</autoref> \| <autoref identifier="typing.Literal" optional>Literal</autoref>["regular"]</code> <span style="float: right;"><b>DEFAULT:</b> <code>VacuumType.PLASMA</code></span>
////
///

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/configuration/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def some_function():

## `preload_modules`

- **:octicons-package-24: Type <code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="str">str</span>] | None</code> :material-equal: `None`{ title="default value" }**
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] | None</code> :material-equal: `None`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

Pre-load modules that are not specified directly in [autodoc instructions][autodoc syntax] (`::: identifier`).
Expand Down
12 changes: 6 additions & 6 deletions docs/usage/configuration/members.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## `members`

- **:octicons-package-24: Type <code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="str">str</span>] |
<span data-autorefs-optional="bool">bool</span> | None</code> :material-equal: `None`{ title="default value" }**
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] |
<autoref identifier="bool" optional>bool</autoref> | None</code> :material-equal: `None`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

An explicit list of members to render.
Expand Down Expand Up @@ -97,8 +97,8 @@ INFO: **The default behavior (with unspecified `members` or `members: null`) is

## `inherited_members`

- **:octicons-package-24: Type <code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="str">str</span>] |
<span data-autorefs-optional="bool">bool</span></code> :material-equal: `False`{ title="default value" }**
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] |
<autoref identifier="bool" optional>bool</autoref></code> :material-equal: `False`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

An explicit list of inherited members (for classes) to render.
Expand Down Expand Up @@ -331,7 +331,7 @@ def function_c():

## `filters`

- **:octicons-package-24: Type <code><span data-autorefs-optional="list">list</span>[<span data-autorefs-optional="str">str</span>] | None</code> :material-equal: `["!^_[^_]"]`{ title="default value" }**
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] | None</code> :material-equal: `["!^_[^_]"]`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

A list of filters applied to filter objects based on their name.
Expand Down Expand Up @@ -555,7 +555,7 @@ package
[:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } &mdash;
[:octicons-tag-24: Insiders 1.2.0](../../insiders/changelog.md#1.2.0)

- **:octicons-package-24: Type <code><span data-autorefs-optional="bool">bool</span> | <span data-autorefs-optional="dict">dict</span>[<span data-autorefs-optional="str">str</span>, <span data-autorefs-optional="bool">bool</span>]</code> :material-equal: `False`{ title="default value" }**
- **:octicons-package-24: Type <code><autoref identifier="bool" optional>bool</autoref> | <autoref identifier="dict" optional>dict</autoref>[<autoref identifier="str" optional>str</autoref>, <autoref identifier="bool" optional>bool</autoref>]</code> :material-equal: `False`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

Whether to render summaries of modules, classes, functions (methods) and attributes.
Expand Down
7 changes: 5 additions & 2 deletions src/mkdocstrings_handlers/python/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ def do_crossref(path: str, *, brief: bool = True) -> Markup:
full_path = path
if brief:
path = full_path.split(".")[-1]
return Markup("<span data-autorefs-optional-hover={full_path}>{path}</span>").format(full_path=full_path, path=path)
return Markup("<autoref identifier={full_path} optional hover>{path}</autoref>").format(
full_path=full_path,
path=path,
)


@lru_cache
Expand Down Expand Up @@ -327,7 +330,7 @@ def repl(match: Match) -> str:
path = match.group()
path_var = f"path{group_number}"
variables[path_var] = path
return f"<span data-autorefs-optional-hover={{{path_var}}}>{{{path_var}}}</span>"
return f"<autoref identifier={{{path_var}}} optional hover>{{{path_var}}}</autoref>"

text = re.sub(r"([\w.]+)", repl, text)
if code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Context:
<tbody>
{% for attribute in section.value %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ attribute.name }}">{{ attribute.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ attribute.name }}" optional hover>{{ attribute.name }}</autoref></code></td>
<td>
{% if attribute.annotation %}
{% with expression = attribute.annotation %}
Expand All @@ -58,7 +58,7 @@ Context:
<ul>
{% for attribute in section.value %}
<li class="doc-section-item field-body">
<b><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ attribute.name }}">{{ attribute.name }}</span></code></b>
<b><code><autoref identifier="{{ obj.path }}.{{ attribute.name }}" optional hover>{{ attribute.name }}</autoref></code></b>
{% if attribute.annotation %}
{% with expression = attribute.annotation %}
(<code>{% include "expression"|get_template with context %}</code>)
Expand All @@ -85,7 +85,7 @@ Context:
<tbody>
{% for attribute in section.value %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ attribute.name }}">{{ attribute.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ attribute.name }}" optional hover>{{ attribute.name }}</autoref></code></td>
<td class="doc-attribute-details">
<div class="doc-md-description">
{{ attribute.description|convert_markdown(heading_level, html_id) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Context:
<tbody>
{% for class in section.value %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ class.name }}">{{ class.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ class.name }}" optional hover>{{ class.name }}</autoref></code></td>
<td>
<div class="doc-md-description">
{{ class.description|convert_markdown(heading_level, html_id) }}
Expand All @@ -50,7 +50,7 @@ Context:
<ul>
{% for class in section.value %}
<li class="doc-section-item field-body">
<b><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ class.name }}">{{ class.name }}</span></code></b>
<b><code><autoref identifier="{{ obj.path }}.{{ class.name }}" optional hover>{{ class.name }}</autoref></code></b>
<div class="doc-md-description">
{{ class.description|convert_markdown(heading_level, html_id) }}
Expand All @@ -72,7 +72,7 @@ Context:
<tbody>
{% for class in section.value %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ class.name }}">{{ class.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ class.name }}" optional hover>{{ class.name }}</autoref></code></td>
<td class="doc-class-details">
<div class="doc-md-description">
{{ class.description|convert_markdown(heading_level, html_id) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Context:
{% for function in section.value %}
{% if not function.name == "__init__" or not config.merge_init_into_class %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ function.name }}">{{ function.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ function.name }}" optional hover>{{ function.name }}</autoref></code></td>
<td>
<div class="doc-md-description">
{{ function.description|convert_markdown(heading_level, html_id) }}
Expand All @@ -53,7 +53,7 @@ Context:
{% for function in section.value %}
{% if not function.name == "__init__" or not config.merge_init_into_class %}
<li class="doc-section-item field-body">
<b><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ function.name }}">{{ function.name }}</span></code></b>
<b><code><autoref identifier="{{ obj.path }}.{{ function.name }}" optional hover>{{ function.name }}</autoref></code></b>
<div class="doc-md-description">
{{ function.description|convert_markdown(heading_level, html_id) }}
Expand All @@ -77,7 +77,7 @@ Context:
{% for function in section.value %}
{% if not function.name == "__init__" or not config.merge_init_into_class %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ function.name }}">{{ function.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ function.name }}" optional hover>{{ function.name }}</autoref></code></td>
<td class="doc-function-details">
<div class="doc-md-description">
{{ function.description|convert_markdown(heading_level, html_id) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Context:
<tbody>
{% for module in section.value %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ module.name }}">{{ module.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ module.name }}" optional hover>{{ module.name }}</autoref></code></td>
<td>
<div class="doc-md-description">
{{ module.description|convert_markdown(heading_level, html_id) }}
Expand All @@ -50,7 +50,7 @@ Context:
<ul>
{% for module in section.value %}
<li class="doc-section-item field-body">
<b><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ module.name }}">{{ module.name }}</span></code></b>
<b><code><autoref identifier="{{ obj.path }}.{{ module.name }}" optional hover>{{ module.name }}</autoref></code></b>
<div class="doc-md-description">
{{ module.description|convert_markdown(heading_level, html_id) }}
Expand All @@ -72,7 +72,7 @@ Context:
<tbody>
{% for module in section.value %}
<tr class="doc-section-item">
<td><code><span data-autorefs-optional-hover="{{ obj.path }}.{{ module.name }}">{{ module.name }}</span></code></td>
<td><code><autoref identifier="{{ obj.path }}.{{ module.name }}" optional hover>{{ module.name }}</autoref></code></td>
<td class="doc-module-details">
<div class="doc-md-description">
{{ module.description|convert_markdown(heading_level, html_id) }}
Expand Down
Loading

0 comments on commit 5705c00

Please sign in to comment.