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

0 commit comments

Comments
 (0)