Skip to content

Commit 93541f2

Browse files
authored
Use <code> for default values, sample values, and choice values (#42)
* Use <code> for default values, sample values, and choice values. * Also format samples. * Update baseline tests. * Also ignore official roles.
1 parent 550027e commit 93541f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+202
-156
lines changed

Diff for: changelogs/fragments/42-code-rendering.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- "Use code formatting for all values, such as choice entries, defaults, and samples (https://github.com/ansible-community/antsibull-docs/issues/38, https://github.com/ansible-community/antsibull-docs/pull/42)."

Diff for: src/antsibull_docs/data/docsite/macros/choiceslist.rst.j2

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% if choices is mapping %}
99
{% for choice, desc in choices | dictsort %}
1010
{% if not has_no_default and ((default_value is not list and default_value == choice) or (default_value is list and choice in default_value)) %}
11-
- :ansible-option-default-bold:`@{ choice | antsibull_to_json | rst_escape(escape_ending_whitespace=true) }@` :ansible-option-default:`(default)`\ :
11+
- :ansible-option-choices-entry-default:`@{ choice | antsibull_to_json | rst_escape(escape_ending_whitespace=true) }@` :ansible-option-choices-default-mark:`(default)`\ :
1212
{% else %}
1313
- :ansible-option-choices-entry:`@{ choice | antsibull_to_json | rst_escape(escape_ending_whitespace=true) }@`\ :
1414
{% endif %}
@@ -20,7 +20,7 @@
2020
{% else %}
2121
{% for choice in choices %}
2222
{% if not has_no_default and ((default_value is not list and default_value == choice) or (default_value is list and choice in default_value)) %}
23-
- :ansible-option-default-bold:`@{ choice | antsibull_to_json | rst_escape(escape_ending_whitespace=true) }@` :ansible-option-default:`← (default)`
23+
- :ansible-option-choices-entry-default:`@{ choice | antsibull_to_json | rst_escape(escape_ending_whitespace=true) }@` :ansible-option-choices-default-mark:`← (default)`
2424
{% else %}
2525
- :ansible-option-choices-entry:`@{ choice | antsibull_to_json | rst_escape(escape_ending_whitespace=true) }@`
2626
{% endif %}
@@ -35,9 +35,9 @@
3535
{% for choice, desc in choices | dictsort %}
3636
<li>
3737
{% if not has_no_default and ((default_value is not list and default_value == choice) or (default_value is list and choice in default_value)) %}
38-
<p><span class="ansible-option-default-bold">@{ choice | antsibull_to_json | escape }@</span> <span class="ansible-option-default">(default)</span>:
38+
<p><code class="ansible-value literal notranslate ansible-option-default-bold">@{ choice | antsibull_to_json | escape }@</code> <span class="ansible-option-choices-default-mark">(default)</span>:
3939
{% else %}
40-
<p><span class="ansible-option-choices-entry">@{ choice | antsibull_to_json | escape }@</span>:
40+
<p><code class="ansible-value literal notranslate ansible-option-choices-entry">@{ choice | antsibull_to_json | escape }@</code>:
4141
{% endif %}
4242
@{ desc | first | default('') | html_ify | indent(10, blank=true) }@</p>
4343
{% for line in desc[1:] %}
@@ -48,9 +48,9 @@
4848
{% else %}
4949
{% for choice in choices %}
5050
{% if not has_no_default and ((default_value is not list and default_value == choice) or (default_value is list and choice in default_value)) %}
51-
<li><p><span class="ansible-option-default-bold">@{ choice | antsibull_to_json | escape }@</span> <span class="ansible-option-default">← (default)</span></p></li>
51+
<li><p><code class="ansible-value literal notranslate ansible-option-default-bold">@{ choice | antsibull_to_json | escape }@</code> <span class="ansible-option-choices-default-mark">← (default)</span></p></li>
5252
{% else %}
53-
<li><p><span class="ansible-option-choices-entry">@{ choice | antsibull_to_json | escape }@</span></p></li>
53+
<li><p><code class="ansible-value literal notranslate ansible-option-choices-entry">@{ choice | antsibull_to_json | escape }@</code></p></li>
5454
{% endif %}
5555
{% endfor %}
5656
{% endif %}

Diff for: src/antsibull_docs/data/docsite/macros/parameters.rst.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
{% endif %}
226226
{# Show default value, when multiple choice or no choices #}
227227
{% if value['default'] is not none and value['default'] not in value['choices'] %}
228-
<p class="ansible-option-line"><span class="ansible-option-default-bold">Default:</span> <span class="ansible-option-default">@{ value['default'] | antsibull_to_json | escape | indent(6, blank=true) }@</span></p>
228+
<p class="ansible-option-line"><span class="ansible-option-default-bold">Default:</span> <code class="ansible-value literal notranslate ansible-option-default">@{ value['default'] | antsibull_to_json | escape | indent(6, blank=true) }@</code></p>
229229
{% endif %}
230230
{# Configuration #}
231231
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['cli']) %}

Diff for: src/antsibull_docs/data/docsite/macros/returnvalues.rst.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
.. rst-class:: ansible-option-line
8585
.. rst-class:: ansible-option-sample
8686

87-
:ansible-option-sample-bold:`Sample:` @{ value['sample'] | antsibull_to_json | rst_escape | indent(6) }@
87+
:ansible-option-sample-bold:`Sample:` :ansible-rv-sample-value:`@{ value['sample'] | antsibull_to_json | rst_escape(escape_ending_whitespace=true) | indent(6, blank=true) }@`
8888
{% endif %}
8989

9090

@@ -145,7 +145,7 @@
145145
@{ choices_html(value['choices'], has_no_default=True) }@
146146
{% endif %}
147147
{% if value['sample'] is not none %}
148-
<p class="ansible-option-line ansible-option-sample"><span class="ansible-option-sample-bold">Sample:</span> @{ value['sample'] | antsibull_to_json | escape | indent(6, blank=true) }@</p>
148+
<p class="ansible-option-line ansible-option-sample"><span class="ansible-option-sample-bold">Sample:</span> <code class="ansible-value literal notranslate ansible-option-sample">@{ value['sample'] | antsibull_to_json | escape | indent(6, blank=true) }@</code></p>
149149
{% endif %}
150150
</div></td>
151151
</tr>

Diff for: src/antsibull_docs/data/docsite/plugin.rst.j2

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
.. role:: ansible-option-versionadded
3333
.. role:: ansible-option-aliases
3434
.. role:: ansible-option-choices
35-
.. role:: ansible-option-choices-entry
36-
.. role:: ansible-option-default
35+
.. role:: ansible-option-choices-default-mark
3736
.. role:: ansible-option-default-bold
3837
.. role:: ansible-option-configuration
3938
.. role:: ansible-option-returned-bold

Diff for: src/antsibull_docs/data/docsite/role.rst.j2

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
.. role:: ansible-option-versionadded
2121
.. role:: ansible-option-aliases
2222
.. role:: ansible-option-choices
23-
.. role:: ansible-option-choices-entry
24-
.. role:: ansible-option-default
23+
.. role:: ansible-option-choices-default-mark
2524
.. role:: ansible-option-default-bold
2625

2726
{# If we can put together source and github repo, we could make the Edit me of github button work.

Diff for: src/antsibull_docs/lint_extra_docs.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import re
1111
import typing as t
1212

13+
from sphinx_antsibull_ext import roles as antsibull_roles
14+
1315
from .extra_docs import (
1416
find_extra_docs,
1517
lint_required_conditions,
@@ -33,7 +35,7 @@ def lint_optional_conditions(content: str, path: str, collection_name: str
3335
3436
Return a list of errors.
3537
'''
36-
return check_rst_content(content, filename=path)
38+
return check_rst_content(content, filename=path, ignore_roles=list(antsibull_roles.ROLES))
3739

3840

3941
def lint_collection_extra_docs_files(path_to_collection: str

Diff for: src/antsibull_docs/lint_plugin_docs.py

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from antsibull_core.compat import asyncio_run
1616
from antsibull_core.venv import FakeVenvRunner
1717

18+
from sphinx_antsibull_ext import roles as antsibull_roles
19+
1820
from .lint_helpers import (
1921
load_collection_info,
2022
)
@@ -161,6 +163,7 @@ def _lint_collection_plugin_docs(collections_dir: str, collection_name: str,
161163
rst_results = check_rst_content(
162164
rst_content, filename=path,
163165
ignore_directives=['rst-class'],
166+
ignore_roles=list(antsibull_roles.ROLES),
164167
)
165168
result.extend([(path, result[0], result[1], result[2]) for result in rst_results])
166169
return result

Diff for: src/sphinx_antsibull_ext/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
from .assets import setup_assets
17+
from .roles import setup_roles
1718

1819

1920
def setup(app):
@@ -25,6 +26,9 @@ def setup(app):
2526
# Add assets
2627
setup_assets(app)
2728

29+
# Add roles
30+
setup_roles(app)
31+
2832
return dict(
2933
parallel_read_safe=True,
3034
parallel_write_safe=True,

Diff for: src/sphinx_antsibull_ext/antsibull-minimal.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/sphinx_antsibull_ext/css/antsibull-minimal.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ table.ansible-option-table {
172172
.ansible-option-choices-entry {
173173
}
174174

175-
.ansible-option-default {
175+
.ansible-option-default, .ansible-option-choices-default-mark {
176176
color: blue;
177177
}
178178

0 commit comments

Comments
 (0)