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+
2940def 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+
7395def 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