Skip to content

Commit 2f61654

Browse files
committed
Also format samples.
1 parent a8fd303 commit 2f61654

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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>

src/sphinx_antsibull_ext/roles.py

+20
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,30 @@ def option_default(name, rawtext, text, lineno, inliner, options={}, content=[])
6767
return [nodes.literal(rawtext, text, classes=['ansible-option-default'])], []
6868

6969

70+
# pylint:disable-next=unused-argument,dangerous-default-value
71+
def return_value_sample(name, rawtext, text, lineno, inliner, options={}, content=[]):
72+
"""Format Ansible return value sample value.
73+
74+
Returns 2 part tuple containing list of nodes to insert into the
75+
document and a list of system messages. Both are allowed to be
76+
empty.
77+
78+
:param name: The role name used in the document.
79+
:param rawtext: The entire markup snippet, with role.
80+
:param text: The text marked with the role.
81+
:param lineno: The line number where rawtext appears in the input.
82+
:param inliner: The inliner instance that called us.
83+
:param options: Directive options for customization.
84+
:param content: The directive content for customization.
85+
"""
86+
return [nodes.literal(rawtext, text, classes=['ansible-option-sample'])], []
87+
88+
7089
ROLES = {
7190
'ansible-option-choices-entry': option_choice,
7291
'ansible-option-choices-entry-default': option_choice_default,
7392
'ansible-option-default': option_default,
93+
'ansible-rv-sample-value': return_value_sample,
7494
}
7595

7696

0 commit comments

Comments
 (0)