Skip to content

Commit b3dc5cd

Browse files
committed
Add semantic markup support.
1 parent f009a2f commit b3dc5cd

File tree

9 files changed

+51
-1
lines changed

9 files changed

+51
-1
lines changed

antsibull/data/docsite/list_of_collections_by_namespace.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
:orphan:
33
{% endif %}
44

5+
.. |equalsign| unicode:: 0x3D .. equal sign
6+
:trim:
7+
58
.. _list_of_collections_@{ namespace }@:
69

710
{% set title = 'Collections in the ' ~ (namespace | title) ~ ' Namespace' | rst_ify -%}

antsibull/data/docsite/list_of_plugins.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
:orphan:
22

3+
.. |equalsign| unicode:: 0x3D .. equal sign
4+
:trim:
5+
36
.. _list_of_@{ plugin_type }@_plugins:
47

58
{% if plugin_type == 'module' %}

antsibull/data/docsite/plugin-deprecation.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
{# avoids rST "isn't included in any toctree" errors for module docs #}
44
:orphan:
55

6+
.. |equalsign| unicode:: 0x3D .. equal sign
7+
:trim:
8+
69
.. _@{ module }@_@{ plugin_type }@_alias_@{ alias }@:
710

811
{% if short_description %}

antsibull/data/docsite/plugin-redirect.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
:orphan:
44

5+
.. |equalsign| unicode:: 0x3D .. equal sign
6+
:trim:
7+
58
.. Anchors
69

710
.. _ansible_collections.@{plugin_name}@_@{plugin_type}@:

antsibull/data/docsite/plugin-tombstone.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
:orphan:
44

5+
.. |equalsign| unicode:: 0x3D .. equal sign
6+
:trim:
7+
58
.. Anchors
69

710
.. _ansible_collections.@{plugin_name}@_@{plugin_type}@:

antsibull/data/docsite/plugin.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
:orphan:
44

5+
.. |equalsign| unicode:: 0x3D .. equal sign
6+
:trim:
7+
58
{# If we can put together source and github repo, we could make the Edit me of github button work.
69
See meta.get("source") in Ansible's docs/docsite/_themes/sphinx_rtd_theme/breadcrumbs.html
710
for more information

antsibull/data/docsite/plugins_by_collection.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
:orphan:
33
{% endif %}
44

5+
.. |equalsign| unicode:: 0x3D .. equal sign
6+
:trim:
7+
58
.. _plugins_in_@{collection_name}@:
69

710
@{collection_name.title()}@

antsibull/data/docsite/role.rst.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
:orphan:
44

5+
.. |equalsign| unicode:: 0x3D .. equal sign
6+
:trim:
7+
58
{# If we can put together source and github repo, we could make the Edit me of github button work.
69
See meta.get("source") in Ansible's docs/docsite/_themes/sphinx_rtd_theme/breadcrumbs.html
710
for more information

antsibull/jinja2/filters.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@
1919
_ITALIC = re.compile(r"\bI\(([^)]+)\)")
2020
_BOLD = re.compile(r"\bB\(([^)]+)\)")
2121
_MODULE = re.compile(r"\bM\(([^)]+)\)")
22+
_PLUGIN = re.compile(r"\bP\(([^#)]+)#([a-z]+)\)")
2223
_URL = re.compile(r"\bU\(([^)]+)\)")
2324
_LINK = re.compile(r"\bL\(([^)]+), *([^)]+)\)")
2425
_REF = re.compile(r"\bR\(([^)]+), *([^)]+)\)")
2526
_CONST = re.compile(r"\bC\(([^)]+)\)")
27+
_SEM_OPTION_NAME = re.compile(r"\bO\(([^)]+)\)")
28+
_SEM_OPTION_VALUE = re.compile(r"\bV\(([^)]+)\)")
29+
_SEM_ENV_VARIABLE = re.compile(r"\bE\(([^)]+)\)")
2630
_RULER = re.compile(r"\bHORIZONTALLINE\b")
2731

2832

33+
def _option_name_html(matcher):
34+
parts = matcher.group(1).split('=', 1)
35+
if len(parts) == 1:
36+
return f'<em>{parts[0]}</em>'
37+
return f'<em>{parts[0]}</em>=<code>{parts[1]}</code>'
38+
39+
2940
def html_ify(text):
3041
''' convert symbols like I(this is in italics) to valid HTML '''
3142

@@ -36,11 +47,15 @@ def html_ify(text):
3647
text = html_escape(text)
3748
text, _counts['italic'] = _ITALIC.subn(r"<em>\1</em>", text)
3849
text, _counts['bold'] = _BOLD.subn(r"<b>\1</b>", text)
39-
text, _counts['module'] = _MODULE.subn(r"<span class='module'>\1</span>", text)
50+
text, _counts['module'] = _MODULE.subn(r"<span class='module plugin-module'>\1</span>", text)
51+
text, _counts['plugin'] = _PLUGIN.subn(r"<span class='module plugin-\2'>\1</span>", text)
4052
text, _counts['url'] = _URL.subn(r"<a href='\1'>\1</a>", text)
4153
text, _counts['ref'] = _REF.subn(r"<span class='module'>\1</span>", text)
4254
text, _counts['link'] = _LINK.subn(r"<a href='\2'>\1</a>", text)
4355
text, _counts['const'] = _CONST.subn(r"<code>\1</code>", text)
56+
text, _counts['option-name'] = _SEM_OPTION_NAME.subn(_option_name_html, text)
57+
text, _counts['option-value'] = _SEM_OPTION_VALUE.subn(r"<code>\1</code>", text)
58+
text, _counts['environment-var'] = _SEM_ENV_VARIABLE.subn(r"<code>\1</code>", text)
4459
text, _counts['ruler'] = _RULER.subn(r"<hr/>", text)
4560

4661
text = text.strip()
@@ -70,6 +85,13 @@ def do_max(seq):
7085
return max(seq)
7186

7287

88+
def _option_name_rst(matcher):
89+
parts = matcher.group(1).split('=', 1)
90+
if len(parts) == 1:
91+
return f'*{parts[0]}*'
92+
return f'*{parts[0]}* |equalsign| ``{parts[1]}``'
93+
94+
7395
def rst_ify(text):
7496
''' convert symbols like I(this is in italics) to valid restructured text '''
7597

@@ -80,10 +102,14 @@ def rst_ify(text):
80102
text, _counts['italic'] = _ITALIC.subn(r"*\1*", text)
81103
text, _counts['bold'] = _BOLD.subn(r"**\1**", text)
82104
text, _counts['module'] = _MODULE.subn(r":ref:`\1 <ansible_collections.\1_module>`", text)
105+
text, _counts['plugin'] = _PLUGIN.subn(r":ref:`\1 <ansible_collections.\1_\2>`", text)
83106
text, _counts['url'] = _LINK.subn(r"`\1 <\2>`_", text)
84107
text, _counts['ref'] = _URL.subn(r"\1", text)
85108
text, _counts['link'] = _REF.subn(r":ref:`\1 <\2>`", text)
86109
text, _counts['const'] = _CONST.subn(r"``\1``", text)
110+
text, _counts['option-name'] = _SEM_OPTION_NAME.subn(_option_name_rst, text)
111+
text, _counts['option-value'] = _SEM_OPTION_VALUE.subn(r"``\1``", text)
112+
text, _counts['environment-var'] = _SEM_ENV_VARIABLE.subn(r"``\1``", text)
87113
text, _counts['ruler'] = _RULER.subn(f"\n\n{'-' * 13}\n\n", text)
88114

89115
flog.fields(counts=_counts).info('Number of macros converted to rst equivalents')

0 commit comments

Comments
 (0)