Skip to content

Commit

Permalink
Use correct length also for wide Unicode letters for title underlines. (
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Dec 16, 2023
1 parent f07e5ff commit ad769b9
Show file tree
Hide file tree
Showing 32 changed files with 51 additions and 42 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/229-title-width.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "Make sure that title underlines have the correct width for wide Unicode characters (https://github.com/ansible-community/antsibull-docs/issues/228, https://github.com/ansible-community/antsibull-docs/pull/229)."
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
.. _list_of_@{ callback_type }@_callback_plugins:

Index of all @{ callback_type | capitalize }@ Callback Plugins
=============@{ '=' * (callback_type | length) }@=================
=============@{ '=' * (callback_type | column_width) }@=================

See :ref:`list_of_callback_plugins` for the list of *all* callback plugins.

{% for collection_name, plugins in per_collection_plugins.items() | sort %}
@{ collection_name }@
@{ '-' * (collection_name | length) }@
@{ '-' * (collection_name | column_width) }@

{% for plugin_name, plugin_desc in plugins.items() | sort %}
* :ansplugin:`@{ collection_name }@.@{ plugin_name }@#callback` -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type='callback') }@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% set title = 'Collections in the ' ~ (namespace | title) ~ ' Namespace' | rst_ify -%}

@{ title }@
@{ '=' * title|length }@
@{ '=' * title|column_width }@

{% if for_official_docsite %}
These are the collections with docs hosted on `docs.ansible.com <https://docs.ansible.com/>`_ in the **@{ namespace }@** namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Index of all Roles
==================
{% else %}
Index of all @{ plugin_type | capitalize }@ Plugins
=============@{ '=' * (plugin_type | length) }@========
=============@{ '=' * (plugin_type | column_width) }@========
{% endif %}
{% if plugin_type == 'callback' %}

Expand All @@ -34,7 +34,7 @@ Index of all @{ plugin_type | capitalize }@ Plugins

{% for collection_name, plugins in per_collection_plugins.items() | sort %}
@{ collection_name }@
@{ '-' * (collection_name | length) }@
@{ '-' * (collection_name | column_width) }@

{% for plugin_name, plugin_desc in plugins.items() | sort %}
* :ansplugin:`@{ collection_name }@.@{ plugin_name }@#@{ plugin_type }@` -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type=plugin_type) }@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{% endif %}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

This is an alias for the :ref:`@{ module }@ @{ plugin_type }@ <@{ module }@_@{ plugin_type }@>`.
This name has been **deprecated**. Please update your tasks to use the new name ``@{ module }@`` instead.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% set title = plugin_name ~ ' ' ~ plugin_type -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@


The documentation for the @{ plugin_type }@ plugin, @{ plugin_name }@, was malformed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% set title = plugin_name ~ ' ' ~ plugin_type -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

.. Collection note

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.. Title

@{ plugin_name }@
@{ '+' * plugin_name|length }@
@{ '+' * plugin_name|column_width }@

.. Collection note

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{% endif -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

.. Collection note

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
.. _plugins_in_@{collection_name}@:

@{collection_name.title()}@
@{ '=' * (collection_name | length) }@
@{ '=' * (collection_name | column_width) }@

{% if collection_version %}
Collection version @{ collection_version }@
Expand Down Expand Up @@ -104,7 +104,7 @@ Communication

{% for section in extra_docs_sections %}
@{section.title}@
@{ '-' * (section.title | length) }@
@{ '-' * (section.title | column_width) }@

{% if section.toctree %}
.. toctree::
Expand Down Expand Up @@ -137,7 +137,7 @@ Modules
~~~~~~~
{% else %}
@{ category | capitalize }@ Plugins
@{ '~' * ((category | length) + 8) }@
@{ '~' * ((category | column_width) + 8) }@
{% endif %}

@{ list_plugins(category) }@
Expand Down
4 changes: 2 additions & 2 deletions src/antsibull_docs/data/docsite/ansible-docsite/role.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{% endif -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

.. Collection note

Expand Down Expand Up @@ -74,7 +74,7 @@
{% endif -%}

@{ title }@
@{ '-' * title|length }@
@{ '-' * title|column_width }@

.. version_added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
.. Created with antsibull-docs @{ antsibull_docs_version }@

Index of all @{ callback_type | capitalize }@ Callback Plugins
=============@{ '=' * (callback_type | length) }@=================
=============@{ '=' * (callback_type | column_width) }@=================

See `List of all Callback Plugins <index_callback.rst>`_ for the list of *all* callback plugins.

{% for collection_name, plugins in per_collection_plugins.items() | sort %}
@{ collection_name }@
@{ '-' * (collection_name | length) }@
@{ '-' * (collection_name | column_width) }@

{% for plugin_name, plugin_desc in plugins.items() | sort %}
* `@{ collection_name }@.@{ plugin_name }@ <@{ collection_name | replace('.', '/') }@/@{ get_plugin_filename(collection_name ~ '.' ~ plugin_name, 'callback') }@>`_ -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type='callback') }@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% set title = 'Collections in the ' ~ (namespace | title) ~ ' Namespace' | rst_ify -%}

@{ title }@
@{ '=' * title|length }@
@{ '=' * title|column_width }@

{% if for_official_docsite %}
These are the collections with docs hosted on `docs.ansible.com <https://docs.ansible.com/>`_ in the **@{ namespace }@** namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Index of all Roles
==================
{% else %}
Index of all @{ plugin_type | capitalize }@ Plugins
=============@{ '=' * (plugin_type | length) }@========
=============@{ '=' * (plugin_type | column_width) }@========
{% endif %}

{% for collection_name, plugins in per_collection_plugins.items() | sort %}
@{ collection_name }@
@{ '-' * (collection_name | length) }@
@{ '-' * (collection_name | column_width) }@

{% for plugin_name, plugin_desc in plugins.items() | sort %}
* `@{ collection_name }@.@{ plugin_name }@ <@{ collection_name | replace('.', '/') }@/@{ get_plugin_filename(collection_name ~ '.' ~ plugin_name, plugin_type) }@>`_ -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type=plugin_type) }@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endif %}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

This is an alias for the @{ module }@ @{ plugin_type }@.
This name has been **deprecated**. Please update your tasks to use the new name ``@{ module }@`` instead.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% set title = plugin_name ~ ' ' ~ plugin_type -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

The documentation for the @{ plugin_type }@ plugin, @{ plugin_name }@, was malformed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% set title = plugin_name ~ ' ' ~ plugin_type -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

{% if collection == 'ansible.builtin' -%}
- This redirect is part of ``ansible-core`` and included in all Ansible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.. Created with antsibull-docs @{ antsibull_docs_version }@

@{ plugin_name }@
@{ '+' * plugin_name|length }@
@{ '+' * plugin_name|column_width }@

{% if collection == 'ansible.builtin' -%}
This module was part of ``ansible-core`` and was included in all Ansible installations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{% endif -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

{% if collection == 'ansible.builtin' -%}
This {% if plugin_type == 'module' %}module{% else %}@{ plugin_type }@ plugin{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% endmacro %}

@{collection_name.title()}@
@{ '=' * (collection_name | length) }@
@{ '=' * (collection_name | column_width) }@

{% if collection_version %}
Collection version @{ collection_version }@
Expand Down Expand Up @@ -82,7 +82,7 @@ Communication

{% for section in extra_docs_sections %}
@{section.title}@
@{ '-' * (section.title | length) }@
@{ '-' * (section.title | column_width) }@

{% if section.toctree %}
{% for toctree_entry in section.toctree %}
Expand Down Expand Up @@ -112,7 +112,7 @@ Modules
~~~~~~~
{% else %}
@{ category | capitalize }@ Plugins
@{ '~' * ((category | length) + 8) }@
@{ '~' * ((category | column_width) + 8) }@
{% endif %}

@{ list_plugins(category) }@
Expand Down
4 changes: 2 additions & 2 deletions src/antsibull_docs/data/docsite/simplified-rst/role.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endif -%}

@{ title }@
@{ '+' * title|length }@
@{ '+' * title|column_width }@

{% if collection == 'ansible.builtin' -%}
This role is part of ``ansible-core`` and included in all Ansible
Expand Down Expand Up @@ -50,7 +50,7 @@ To use it in a playbook, specify: :code:`@{plugin_name}@`.
{% endif -%}

@{ title }@
@{ '-' * title|length }@
@{ '-' * title|column_width }@

{% if ep_doc['version_added'] is still_relevant(collection=collection) -%}
New in @{ version_added_rst(ep_doc['version_added'], collection) }@
Expand Down
2 changes: 2 additions & 0 deletions src/antsibull_docs/jinja2/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from . import FilenameGenerator, OutputFormat
from .filters import (
collection_name,
column_width,
documented_type,
extract_options_from_list,
html_ify,
Expand Down Expand Up @@ -152,6 +153,7 @@ def doc_environment(
env.filters["antsibull_to_json"] = to_json
env.filters["antsibull_to_ini_value"] = to_ini_value
env.filters["collection_name"] = collection_name
env.filters["column_width"] = column_width
env.filters["plugin_shortname"] = plugin_shortname
env.filters["suboption_depth"] = suboption_depth
env.filters["rst_format"] = rst_format
Expand Down
5 changes: 5 additions & 0 deletions src/antsibull_docs/jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from collections.abc import Mapping, Sequence

from antsibull_core.logging import log
from docutils.utils import column_width as _column_width # pyre-ignore[21]
from jinja2.runtime import Context, Undefined
from jinja2.utils import pass_context

Expand Down Expand Up @@ -251,3 +252,7 @@ def rst_format(fmt: str, for_sphinx: bool = False) -> str:
return "json"
# Unknown format: no syntax highlighting
return "text"


def column_width(string: str) -> int:
return _column_width(string)
2 changes: 1 addition & 1 deletion tests/functional/ansible-doc-cache-all-others.json
Original file line number Diff line number Diff line change
Expand Up @@ -23423,7 +23423,7 @@
"description": [
"This is the baz entrypoint of the bar role."
],
"short_description": "Bar role, baz entrypoint"
"short_description": "Bar role, baz entrypoint \u30c6\u30b9\u30c8\u30ed\u30fc\u30eb"
},
"main": {
"author": [
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/ansible-doc-cache-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -23342,7 +23342,7 @@
"description": [
"This is the baz entrypoint of the bar role."
],
"short_description": "Bar role, baz entrypoint"
"short_description": "Bar role, baz entrypoint \u30c6\u30b9\u30c8\u30ed\u30fc\u30eb"
},
"main": {
"author": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23226,7 +23226,7 @@
"description": [
"This is the baz entrypoint of the bar role."
],
"short_description": "Bar role, baz entrypoint"
"short_description": "Bar role, baz entrypoint \u30c6\u30b9\u30c8\u30ed\u30fc\u30eb"
},
"main": {
"author": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@
"description": [
"This is the baz entrypoint of the bar role."
],
"short_description": "Bar role, baz entrypoint"
"short_description": "Bar role, baz entrypoint \u30c6\u30b9\u30c8\u30ed\u30fc\u30eb"
},
"main": {
"author": [
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/ansible-doc-cache-ns.col2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@
"description": [
"This is the baz entrypoint of the bar role."
],
"short_description": "Bar role, baz entrypoint"
"short_description": "Bar role, baz entrypoint \u30c6\u30b9\u30c8\u30ed\u30fc\u30eb"
},
"main": {
"author": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ ns.col2.bar role -- Bar role

.. Entry point title
Entry point ``baz`` -- Bar role, baz entrypoint
-----------------------------------------------
Entry point ``baz`` -- Bar role, baz entrypoint テストロール
------------------------------------------------------------

.. version_added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ ns.col2.bar role -- Bar role

.. Entry point title
Entry point ``baz`` -- Bar role, baz entrypoint
-----------------------------------------------
Entry point ``baz`` -- Bar role, baz entrypoint テストロール
------------------------------------------------------------

.. version_added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ To use it in a playbook, specify: :code:`ns.col2.bar`.
:depth: 2


Entry point ``baz`` -- Bar role, baz entrypoint
-----------------------------------------------
Entry point ``baz`` -- Bar role, baz entrypoint テストロール
------------------------------------------------------------



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ argument_specs:
- module: ns2.col.foobarbaz
# does not exist
baz:
short_description: Bar role, baz entrypoint
short_description: Bar role, baz entrypoint テストロール
description:
- This is the baz entrypoint of the bar role.

0 comments on commit ad769b9

Please sign in to comment.