Skip to content

Commit af0d964

Browse files
authored
Semantic markup: make sure that FQCN/plugin type is passed on to rst_ify/html_ify outside of plugin pages (#105)
* Allow to pass in FQCN/plugin type to rst_ify/html_ify filters. * Use new options in templates. * Fix syntax.
1 parent 0793433 commit af0d964

File tree

114 files changed

+2043
-232
lines changed

Some content is hidden

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

114 files changed

+2043
-232
lines changed

src/antsibull_docs/data/docsite/list_of_callback_plugins.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See :ref:`list_of_callback_plugins` for the list of *all* callback plugins.
1818
@{ '-' * (collection_name | length) }@
1919

2020
{% for plugin_name, plugin_desc in plugins.items() | sort %}
21-
* :ref:`@{ collection_name }@.@{ plugin_name }@ <ansible_collections.@{ collection_name }@.@{ plugin_name }@_callback>` -- @{ plugin_desc | rst_ify }@
21+
* :ref:`@{ collection_name }@.@{ plugin_name }@ <ansible_collections.@{ collection_name }@.@{ plugin_name }@_callback>` -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type='callback') }@
2222
{% endfor %}
2323

2424
{% else %}

src/antsibull_docs/data/docsite/list_of_env_variables.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Environment variables used by the ansible-core configuration are documented in :
1919
.. envvar:: @{ env_var.name }@
2020

2121
{% for paragraph in env_var.description or [] %}
22-
@{ paragraph | replace('\n', '\n ') | rst_ify | indent(4) }@
22+
@{ paragraph | replace('\n', '\n ') | rst_ify(plugin_fqcn='', plugin_type='') | indent(4) }@
2323

2424
{% endfor %}
2525
*Used by:*

src/antsibull_docs/data/docsite/list_of_plugins.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Index of all @{ plugin_type | capitalize }@ Plugins
3434
@{ '-' * (collection_name | length) }@
3535

3636
{% for plugin_name, plugin_desc in plugins.items() | sort %}
37-
* :ref:`@{ collection_name }@.@{ plugin_name }@ <ansible_collections.@{ collection_name }@.@{ plugin_name }@_@{ plugin_type }@>` -- @{ plugin_desc | rst_ify }@
37+
* :ref:`@{ collection_name }@.@{ plugin_name }@ <ansible_collections.@{ collection_name }@.@{ plugin_name }@_@{ plugin_type }@>` -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type=plugin_type) }@
3838
{% endfor %}
3939

4040
{% endfor %}

src/antsibull_docs/data/docsite/plugins_by_collection.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
{% macro list_plugins(plugin_type) %}
1212
{% for name, desc in plugin_maps[plugin_type].items() | sort %}
13-
* :ref:`@{ name }@ @{ plugin_type }@ <ansible_collections.@{ collection_name }@.@{ name }@_@{ plugin_type }@>` -- @{ desc | rst_ify | indent(width=2) }@
13+
* :ref:`@{ name }@ @{ plugin_type }@ <ansible_collections.@{ collection_name }@.@{ name }@_@{ plugin_type }@>` -- @{ desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ name, plugin_type=plugin_type) | indent(width=2) }@
1414
{% endfor %}
1515
{% if breadcrumbs %}
1616

src/antsibull_docs/jinja2/filters.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
_EMAIL_ADDRESS = re.compile(r"(?:<{mail}>|\({mail}\)|{mail})".format(mail=r"[\w.+-]+@[\w.-]+\.\w+"))
2020

2121

22-
def extract_plugin_data(context: Context) -> t.Tuple[t.Optional[str], t.Optional[str]]:
23-
plugin_fqcn = context.get('plugin_name')
24-
plugin_type = context.get('plugin_type')
22+
def extract_plugin_data(context: Context,
23+
plugin_fqcn: t.Optional[str] = None,
24+
plugin_type: t.Optional[str] = None
25+
) -> t.Tuple[t.Optional[str], t.Optional[str]]:
26+
plugin_fqcn = context.get('plugin_name') if plugin_fqcn is None else plugin_fqcn
27+
plugin_type = context.get('plugin_type') if plugin_type is None else plugin_type
2528
if plugin_fqcn is None or plugin_type is None:
2629
return None, None
2730
# if plugin_type == 'role':

src/antsibull_docs/jinja2/htmlify.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class _Context:
4242
plugin_fqcn: t.Optional[str]
4343
plugin_type: t.Optional[str]
4444

45-
def __init__(self, j2_context: Context):
45+
def __init__(self, j2_context: Context,
46+
plugin_fqcn: t.Optional[str] = None,
47+
plugin_type: t.Optional[str] = None):
4648
self.j2_context = j2_context
4749
self.counts = {
4850
'italic': 0,
@@ -59,7 +61,8 @@ def __init__(self, j2_context: Context):
5961
'return-value': 0,
6062
'ruler': 0,
6163
}
62-
self.plugin_fqcn, self.plugin_type = extract_plugin_data(j2_context)
64+
self.plugin_fqcn, self.plugin_type = extract_plugin_data(
65+
j2_context, plugin_fqcn=plugin_fqcn, plugin_type=plugin_type)
6366

6467

6568
# In the following, we make heavy use of escaped whitespace ("\ ") being removed from the output.
@@ -295,12 +298,19 @@ def handle(self, parameters: t.List[str], context: t.Any) -> str:
295298

296299

297300
@pass_context
298-
def html_ify(context: Context, text: str) -> str:
301+
def html_ify(context: Context, text: str,
302+
*,
303+
plugin_fqcn: t.Optional[str] = None,
304+
plugin_type: t.Optional[str] = None) -> str:
299305
''' convert symbols like I(this is in italics) to valid HTML '''
300306
flog = mlog.fields(func='html_ify')
301307
flog.fields(text=text).debug('Enter')
302308

303-
our_context = _Context(context)
309+
our_context = _Context(
310+
context,
311+
plugin_fqcn=plugin_fqcn,
312+
plugin_type=plugin_type,
313+
)
304314

305315
try:
306316
text = convert_text(text, _COMMAND_SET, html_escape, our_context)

src/antsibull_docs/jinja2/rstify.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class _Context:
7070
plugin_fqcn: t.Optional[str]
7171
plugin_type: t.Optional[str]
7272

73-
def __init__(self, j2_context: Context):
73+
def __init__(self, j2_context: Context,
74+
plugin_fqcn: t.Optional[str] = None,
75+
plugin_type: t.Optional[str] = None):
7476
self.j2_context = j2_context
7577
self.counts = {
7678
'italic': 0,
@@ -87,7 +89,8 @@ def __init__(self, j2_context: Context):
8789
'return-value': 0,
8890
'ruler': 0,
8991
}
90-
self.plugin_fqcn, self.plugin_type = extract_plugin_data(j2_context)
92+
self.plugin_fqcn, self.plugin_type = extract_plugin_data(
93+
j2_context, plugin_fqcn=plugin_fqcn, plugin_type=plugin_type)
9194

9295

9396
# In the following, we make heavy use of escaped whitespace ("\ ") being removed from the output.
@@ -263,12 +266,19 @@ def handle(self, parameters: t.List[str], context: t.Any) -> str:
263266

264267

265268
@pass_context
266-
def rst_ify(context: Context, text: str) -> str:
269+
def rst_ify(context: Context, text: str,
270+
*,
271+
plugin_fqcn: t.Optional[str] = None,
272+
plugin_type: t.Optional[str] = None) -> str:
267273
''' convert symbols like I(this is in italics) to valid restructured text '''
268274
flog = mlog.fields(func='rst_ify')
269275
flog.fields(text=text).debug('Enter')
270276

271-
our_context = _Context(context)
277+
our_context = _Context(
278+
context,
279+
plugin_fqcn=plugin_fqcn,
280+
plugin_type=plugin_type,
281+
)
272282

273283
try:
274284
text = convert_text(text, _COMMAND_SET, rst_escape, our_context)

tests/functional/baseline-default/collections/callback_index_stdout.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ See :ref:`list_of_callback_plugins` for the list of *all* callback plugins.
1111
ns2.col
1212
-------
1313

14-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_callback>` -- Foo output
14+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_callback>` -- Foo output \ :ansopt:`ns2.col.foo#callback:bar`\
1515

tests/functional/baseline-default/collections/index_become.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Become Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_become>` -- Use foo
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_become>` -- Use foo \ :ansopt:`ns2.col.foo#become:bar`\
1313

tests/functional/baseline-default/collections/index_cache.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Cache Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_cache>` -- Foo files
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_cache>` -- Foo files \ :ansopt:`ns2.col.foo#cache:bar`\
1313

tests/functional/baseline-default/collections/index_callback.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Index of all Callback Plugins
1717
ns2.col
1818
-------
1919

20-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_callback>` -- Foo output
20+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_callback>` -- Foo output \ :ansopt:`ns2.col.foo#callback:bar`\
2121

tests/functional/baseline-default/collections/index_connection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Connection Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_connection>` -- Foo connection
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_connection>` -- Foo connection \ :ansopt:`ns2.col.foo#connection:bar`\
1313

tests/functional/baseline-default/collections/index_filter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Filter Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_filter>` -- The foo filter
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_filter>` -- The foo filter \ :ansopt:`ns2.col.foo#filter:bar`\
1313

tests/functional/baseline-default/collections/index_inventory.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Inventory Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_inventory>` -- The foo inventory
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_inventory>` -- The foo inventory \ :ansopt:`ns2.col.foo#inventory:bar`\
1313

tests/functional/baseline-default/collections/index_lookup.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Lookup Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_lookup>` -- Look up some foo
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_lookup>` -- Look up some foo \ :ansopt:`ns2.col.foo#lookup:bar`\
1313

tests/functional/baseline-default/collections/index_module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ ns.col2
1414
ns2.col
1515
-------
1616

17-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_module>` -- Do some foo
17+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_module>` -- Do some foo \ :ansopt:`ns2.col.foo#module:bar`\
1818
* :ref:`ns2.col.foo2 <ansible_collections.ns2.col.foo2_module>` -- Another foo
1919

tests/functional/baseline-default/collections/index_shell.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Shell Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_shell>` -- Foo shell
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_shell>` -- Foo shell \ :ansopt:`ns2.col.foo#shell:bar`\
1313

tests/functional/baseline-default/collections/index_test.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Test Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_test>` -- Is something a foo
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_test>` -- Is something a foo \ :ansopt:`ns2.col.foo#test:bar`\
1313

tests/functional/baseline-default/collections/index_vars.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Index of all Vars Plugins
99
ns2.col
1010
-------
1111

12-
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_vars>` -- Load foo
12+
* :ref:`ns2.col.foo <ansible_collections.ns2.col.foo_vars>` -- Load foo \ :ansopt:`ns2.col.foo#vars:bar`\
1313

tests/functional/baseline-default/collections/ns2/col/foo_become.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
3838
.. Title
3939
40-
ns2.col.foo become -- Use foo
41-
+++++++++++++++++++++++++++++
40+
ns2.col.foo become -- Use foo \ :ansopt:`ns2.col.foo#become:bar`\
41+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4242

4343
.. Collection note
4444

tests/functional/baseline-default/collections/ns2/col/foo_cache.rst

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
3838
.. Title
3939
40-
ns2.col.foo cache -- Foo files
41-
++++++++++++++++++++++++++++++
40+
ns2.col.foo cache -- Foo files \ :ansopt:`ns2.col.foo#cache:bar`\
41+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4242

4343
.. Collection note
4444
@@ -144,6 +144,43 @@ Parameters
144144
- Environment variable: :envvar:`ANSIBLE\_CACHE\_PLUGIN\_CONNECTION`
145145

146146

147+
.. raw:: html
148+
149+
</div>
150+
151+
* - .. raw:: html
152+
153+
<div class="ansible-option-cell">
154+
<div class="ansibleOptionAnchor" id="parameter-bar"></div>
155+
156+
.. _ansible_collections.ns2.col.foo_cache__parameter-bar:
157+
158+
.. rst-class:: ansible-option-title
159+
160+
**bar**
161+
162+
.. raw:: html
163+
164+
<a class="ansibleOptionLink" href="#parameter-bar" title="Permalink to this option"></a>
165+
166+
.. rst-class:: ansible-option-type-line
167+
168+
:ansible-option-type:`string`
169+
170+
171+
172+
173+
.. raw:: html
174+
175+
</div>
176+
177+
- .. raw:: html
178+
179+
<div class="ansible-option-cell">
180+
181+
Nothing.
182+
183+
147184
.. raw:: html
148185

149186
</div>

tests/functional/baseline-default/collections/ns2/col/foo_callback.rst

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
3838
.. Title
3939
40-
ns2.col.foo callback -- Foo output
41-
++++++++++++++++++++++++++++++++++
40+
ns2.col.foo callback -- Foo output \ :ansopt:`ns2.col.foo#callback:bar`\
41+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4242

4343
.. Collection note
4444
@@ -88,6 +88,57 @@ Synopsis
8888
8989
.. Options
9090
91+
Parameters
92+
----------
93+
94+
95+
.. rst-class:: ansible-option-table
96+
97+
.. list-table::
98+
:width: 100%
99+
:widths: auto
100+
:header-rows: 1
101+
102+
* - Parameter
103+
- Comments
104+
105+
* - .. raw:: html
106+
107+
<div class="ansible-option-cell">
108+
<div class="ansibleOptionAnchor" id="parameter-bar"></div>
109+
110+
.. _ansible_collections.ns2.col.foo_callback__parameter-bar:
111+
112+
.. rst-class:: ansible-option-title
113+
114+
**bar**
115+
116+
.. raw:: html
117+
118+
<a class="ansibleOptionLink" href="#parameter-bar" title="Permalink to this option"></a>
119+
120+
.. rst-class:: ansible-option-type-line
121+
122+
:ansible-option-type:`string`
123+
124+
125+
126+
127+
.. raw:: html
128+
129+
</div>
130+
131+
- .. raw:: html
132+
133+
<div class="ansible-option-cell">
134+
135+
Nothing.
136+
137+
138+
.. raw:: html
139+
140+
</div>
141+
91142

92143
.. Attributes
93144

0 commit comments

Comments
 (0)