Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize RST labels to remove duplicates (for one option) #7

Merged
merged 4 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/7-label-normalization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "Make sure that aliases of module/plugin options and return values that result in identical RST labels under docutil's normalization are only emitted once (https://github.com/ansible-community/antsibull-docs/pull/7)."
- "Properly escape module/plugin option and return value slugs in generated HTML (https://github.com/ansible-community/antsibull-docs/pull/7)."
3 changes: 3 additions & 0 deletions src/antsibull_docs/augment_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def add_full_key(options_data: t.Mapping[str, t.Any], suboption_entry: str,
full_keys_k.extend([fk + [alias] for fk in _full_keys])
entry['full_key'] = full_key_k
entry['full_keys'] = full_keys_k
entry['full_keys_rst'] = sorted({
tuple(' '.join(p.lower().split()) for p in fk) for fk in full_keys_k
})

# Process suboptions
suboptions = entry.get(suboption_entry)
Expand Down
10 changes: 5 additions & 5 deletions src/antsibull_docs/data/docsite/macros/parameters.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

{% for i in range(1, loop.depth) %}<div class="ansible-option-indent"></div>{% endfor %}<div class="ansible-option-cell">
{% for full_key in value['full_keys'] %}
<div class="ansibleOptionAnchor" id="parameter-@{ parameter_html_prefix }@{% for part in full_key %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
<div class="ansibleOptionAnchor" id="parameter-@{ parameter_html_prefix }@{% for part in full_key %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
{% endfor %}

{% for full_key in value['full_keys'] %}
{% for full_key in value['full_keys_rst'] %}
.. _ansible_collections.@{plugin_name}@_@{plugin_type}@__parameter-@{ parameter_rst_prefix }@{% for part in full_key %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}:
{% endfor %}

Expand All @@ -31,7 +31,7 @@

.. raw:: html

<a class="ansibleOptionLink" href="#parameter-@{ parameter_html_prefix }@{% for part in value['full_key'] %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this option"></a>
<a class="ansibleOptionLink" href="#parameter-@{ parameter_html_prefix }@{% for part in value['full_key'] %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this option"></a>
{% if value['aliases'] %}

.. rst-class:: ansible-option-type-line
Expand Down Expand Up @@ -191,10 +191,10 @@
<tr class="row-@{ row_class.next() }@">
<td>{% for i in range(1, loop.depth) %}<div class="ansible-option-indent"></div>{% endfor %}<div class="ansible-option-cell">
{% for full_key in value['full_keys'] %}
<div class="ansibleOptionAnchor" id="parameter-@{ parameter_html_prefix }@{% for part in full_key %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
<div class="ansibleOptionAnchor" id="parameter-@{ parameter_html_prefix }@{% for part in full_key %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
{% endfor %}
<p class="ansible-option-title"><strong>@{ key | escape }@</strong></p>
<a class="ansibleOptionLink" href="#parameter-@{ parameter_html_prefix }@{% for part in value['full_key'] %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this option"></a>
<a class="ansibleOptionLink" href="#parameter-@{ parameter_html_prefix }@{% for part in value['full_key'] %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this option"></a>
{% if value['aliases'] %}
<p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: @{ value['aliases']|join(', ') }@</span></p>
{% endif %}
Expand Down
10 changes: 5 additions & 5 deletions src/antsibull_docs/data/docsite/macros/returnvalues.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

{% for i in range(1, loop.depth) %}<div class="ansible-option-indent"></div>{% endfor %}<div class="ansible-option-cell">
{% for full_key in value['full_keys'] %}
<div class="ansibleOptionAnchor" id="return-{% for part in full_key %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
<div class="ansibleOptionAnchor" id="return-{% for part in full_key %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
{% endfor %}

{% for full_key in value['full_keys'] %}
{% for full_key in value['full_keys_rst'] %}
.. _ansible_collections.@{plugin_name}@_@{plugin_type}@__return-{% for part in full_key %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}:
{% endfor %}

Expand All @@ -28,7 +28,7 @@

.. raw:: html

<a class="ansibleOptionLink" href="#return-{% for part in value['full_key'] %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this return value"></a>
<a class="ansibleOptionLink" href="#return-{% for part in value['full_key'] %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this return value"></a>

.. rst-class:: ansible-option-type-line

Expand Down Expand Up @@ -119,10 +119,10 @@
<tr class="row-@{ row_class.next() }@">
<td>{% for i in range(1, loop.depth) %}<div class="ansible-option-indent"></div>{% endfor %}<div class="ansible-option-cell">
{% for full_key in value['full_keys'] %}
<div class="ansibleOptionAnchor" id="return-{% for part in full_key %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
<div class="ansibleOptionAnchor" id="return-{% for part in full_key %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}"></div>
{% endfor %}
<p class="ansible-option-title"><strong>@{ key | escape }@</strong></p>
<a class="ansibleOptionLink" href="#return-{% for part in value['full_key'] %}@{ part }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this return value"></a>
<a class="ansibleOptionLink" href="#return-{% for part in value['full_key'] %}@{ part | urlencode }@{% if not loop.last %}/{% endif %}{% endfor %}" title="Permalink to this return value"></a>
<p class="ansible-option-type-line">
<span class="ansible-option-type">@{ value['type'] | documented_type }@</span>
{% if value['type'] == 'list' and value['elements'] is not none %}
Expand Down