Skip to content

Commit

Permalink
Improve handling of empty markup parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Jun 30, 2024
1 parent 2a7e443 commit b0d9a2e
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/290-empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- "Improve handling of empty markup parameters for RST (https://github.com/ansible-community/antsibull-docs/pull/290)."
minor_changes:
- "Bump minimum dependency of ``antsibull-docs-parser`` to 1.0.2 or newer (https://github.com/ansible-community/antsibull-docs/pull/290)."
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"ansible-pygments",
"antsibull-changelog >= 0.24.0",
"antsibull-core >= 2.1.0, < 4.0.0",
"antsibull-docs-parser >= 1.0.0, < 2.0.0",
"antsibull-docs-parser >= 1.0.2, < 2.0.0",
"asyncio-pool",
"docutils",
"jinja2 >= 3.0",
Expand Down
10 changes: 8 additions & 2 deletions src/antsibull_docs/markup/rstify.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ def __init__(self, referable_envvars: set[str] | None = None):
def format_env_variable(self, part: dom.EnvVariablePart) -> str:
envvar = part.name.split("=", 1)[0].strip()
if envvar in self._referable_envvars:
return f"\\ :ansenvvarref:`{_rst_escape(part.name, True)}`\\ "
return f"\\ :ansenvvar:`{_rst_escape(part.name, True)}`\\ "
text = _rst_escape(
part.name, escape_ending_whitespace=True, must_not_be_empty=True
)
return f"\\ :ansenvvarref:`{text}`\\ "
text = _rst_escape(
part.name, escape_ending_whitespace=True, must_not_be_empty=True
)
return f"\\ :ansenvvar:`{text}`\\ "


class SimplifiedRSTLinkProvider(LinkProvider):
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/ansible-doc-cache-all-others.json
Original file line number Diff line number Diff line change
Expand Up @@ -22712,7 +22712,8 @@
"The option O(foo) exists, but O(foobar) does not.",
"The return value RV(bar) exists, but RV(barbaz) does not.",
"Again existing: O(ns.col2.foo#module:foo=1), RV(ns.col2.foo#module:bar=2)",
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)"
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)",
"C() I() B() C() U() L(,) R(,) V() O() RV() E()"
],
"filename": "ansible_collections/ns/col2/plugins/modules/foo2.py",
"has_action": false,
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/ansible-doc-cache-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -22629,7 +22629,8 @@
"The option O(foo) exists, but O(foobar) does not.",
"The return value RV(bar) exists, but RV(barbaz) does not.",
"Again existing: O(ns.col2.foo#module:foo=1), RV(ns.col2.foo#module:bar=2)",
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)"
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)",
"C() I() B() C() U() L(,) R(,) V() O() RV() E()"
],
"filename": "ansible_collections/ns/col2/plugins/modules/foo2.py",
"has_action": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22629,7 +22629,8 @@
"The option O(foo) exists, but O(foobar) does not.",
"The return value RV(bar) exists, but RV(barbaz) does not.",
"Again existing: O(ns.col2.foo#module:foo=1), RV(ns.col2.foo#module:bar=2)",
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)"
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)",
"C() I() B() C() U() L(,) R(,) V() O() RV() E()"
],
"filename": "ansible_collections/ns/col2/plugins/modules/foo2.py",
"has_action": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,8 @@
"The option O(foo) exists, but O(foobar) does not.",
"The return value RV(bar) exists, but RV(barbaz) does not.",
"Again existing: O(ns.col2.foo#module:foo=1), RV(ns.col2.foo#module:bar=2)",
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)"
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)",
"C() I() B() C() U() L(,) R(,) V() O() RV() E()"
],
"filename": "ansible_collections/ns/col2/plugins/modules/foo2.py",
"has_action": false,
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/ansible-doc-cache-ns.col2.json
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@
"The option O(foo) exists, but O(foobar) does not.",
"The return value RV(bar) exists, but RV(barbaz) does not.",
"Again existing: O(ns.col2.foo#module:foo=1), RV(ns.col2.foo#module:bar=2)",
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)"
"Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)",
"C() I() B() C() U() L(,) R(,) V() O() RV() E()"
],
"filename": "ansible_collections/ns/col2/plugins/modules/foo2.py",
"has_action": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Synopsis
- The return value \ :ansretval:`ns.col2.foo2#module:bar`\ exists, but \ :ansretval:`ns.col2.foo2#module:barbaz`\ does not.
- Again existing: \ :ansopt:`ns.col2.foo#module:foo=1`\ , \ :ansretval:`ns.col2.foo#module:bar=2`\
- Again not existing: \ :ansopt:`ns.col2.foo#module:foobar=1`\ , \ :ansretval:`ns.col2.foo#module:barbaz=2`\
- \ :literal:`\ `\ \ :emphasis:`\ `\ \ :strong:`\ `\ \ :literal:`\ `\ \ \ \ :ref:`\ <>`\ \ :ansval:`\ `\ \ :ansopt:`ns.col2.foo2#module:`\ \ :ansretval:`ns.col2.foo2#module:`\ \ :ansenvvar:`\ `\


.. Aliases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Synopsis
- The return value \ :ansretval:`ns.col2.foo2#module:bar`\ exists, but \ :ansretval:`ns.col2.foo2#module:barbaz`\ does not.
- Again existing: \ :ansopt:`ns.col2.foo#module:foo=1`\ , \ :ansretval:`ns.col2.foo#module:bar=2`\
- Again not existing: \ :ansopt:`ns.col2.foo#module:foobar=1`\ , \ :ansretval:`ns.col2.foo#module:barbaz=2`\
- \ :literal:`\ `\ \ :emphasis:`\ `\ \ :strong:`\ `\ \ :literal:`\ `\ \ \ \ :ref:`\ <>`\ \ :ansval:`\ `\ \ :ansopt:`ns.col2.foo2#module:`\ \ :ansretval:`ns.col2.foo2#module:`\ \ :ansenvvar:`\ `\


.. Aliases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Synopsis
- The return value \ :literal:`bar` (`link <#return-bar>`_)\ exists, but \ :literal:`barbaz` (`link <#return-barbaz>`_)\ does not.
- Again existing: \ :literal:`foo=1` (of module `ns.col2.foo <foo_module.rst>`__)\ , \ :literal:`bar=2` (of module `ns.col2.foo <foo_module.rst>`__)\
- Again not existing: \ :literal:`foobar=1` (of module `ns.col2.foo <foo_module.rst>`__)\ , \ :literal:`barbaz=2` (of module `ns.col2.foo <foo_module.rst>`__)\
- \ :literal:`\ `\ \ :emphasis:`\ `\ \ :strong:`\ `\ \ :literal:`\ `\ \ \ \ :ref:`\ <>`\ \ :literal:`\ `\ \ :literal:`` (`link <#parameter->`_)\ \ :literal:`` (`link <#return->`_)\ \ :literal:``\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- The return value RV(bar) exists, but RV(barbaz) does not.
- "Again existing: O(ns.col2.foo#module:foo=1), RV(ns.col2.foo#module:bar=2)"
- "Again not existing: O(ns.col2.foo#module:foobar=1), RV(ns.col2.foo#module:barbaz=2)"
- C() I() B() C() U() L(,) R(,) V() O() RV() E()
options:
foo:
description: The foo source.
Expand Down

0 comments on commit b0d9a2e

Please sign in to comment.