From cb1b22715245c2aeadf84a73445fcbab89676273 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 16 Jan 2025 19:41:27 +0100 Subject: [PATCH 1/3] Add test for before-case. --- test-vectors.yaml | 14 ++++++++++++++ tests/unit/test_rst.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test-vectors.yaml b/test-vectors.yaml index 9019874..2a71f85 100644 --- a/test-vectors.yaml +++ b/test-vectors.yaml @@ -1621,3 +1621,17 @@ test_vectors: ------------- x [[ERROR while parsing: While parsing "M(föø \t b\nz \r m)" at index 125: Module name "föø b z m" is not a FQCN]]   `  '`  '*    *`    ' + pipe_symbol: + source: Use C(0)|C(1). + html: |- +

Use 0|1.

+ html_plain: |- +

Use 0|1.

+ md: |- + Use 0\|1\. + rst: |- + Use :literal:`0`\ |\ :literal:`1`. + rst_plain: |- + Use :literal:`0`\ |\ :literal:`1`. + ansible_doc_text: |- + Use `0'|`1'. diff --git a/tests/unit/test_rst.py b/tests/unit/test_rst.py index f54c9e9..62a5674 100644 --- a/tests/unit/test_rst.py +++ b/tests/unit/test_rst.py @@ -17,7 +17,7 @@ def test_rst_escape(): assert rst_escape("") == "" assert rst_escape(" foo ") == " foo " assert rst_escape(" foo ", True) == "\\ foo \\ " - assert rst_escape("\\<_>`*<_>*`\\") == "\\\\\\<\\_\\>\\`\\*\\<\\_\\>\\*\\`\\\\" + assert rst_escape("\\<_>`*<_>*`\\|") == "\\\\\\<\\_\\>\\`\\*\\<\\_\\>\\*\\`\\\\|" def test_postprocess_rst_paragraph(): From 9a2849bd69886fea0a191d488c9efe6c8a45d4fa Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 16 Jan 2025 19:46:35 +0100 Subject: [PATCH 2/3] Escape '|' in RST. --- src/antsibull_docs_parser/rst.py | 1 + test-vectors.yaml | 4 ++-- tests/unit/test_rst.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/antsibull_docs_parser/rst.py b/src/antsibull_docs_parser/rst.py index b610534..cf9aa0c 100644 --- a/src/antsibull_docs_parser/rst.py +++ b/src/antsibull_docs_parser/rst.py @@ -32,6 +32,7 @@ def rst_escape( value = value.replace("_", "\\_") value = value.replace("*", "\\*") value = value.replace("`", "\\`") + value = value.replace("|", "\\|") # RST does not like it when the inside of `...` starts or ends with a whitespace # (here, all kind of whitespaces count, not just spaces...) diff --git a/test-vectors.yaml b/test-vectors.yaml index 2a71f85..37c6167 100644 --- a/test-vectors.yaml +++ b/test-vectors.yaml @@ -1630,8 +1630,8 @@ test_vectors: md: |- Use 0\|1\. rst: |- - Use :literal:`0`\ |\ :literal:`1`. + Use :literal:`0`\ \|\ :literal:`1`. rst_plain: |- - Use :literal:`0`\ |\ :literal:`1`. + Use :literal:`0`\ \|\ :literal:`1`. ansible_doc_text: |- Use `0'|`1'. diff --git a/tests/unit/test_rst.py b/tests/unit/test_rst.py index 62a5674..5f28a18 100644 --- a/tests/unit/test_rst.py +++ b/tests/unit/test_rst.py @@ -17,7 +17,7 @@ def test_rst_escape(): assert rst_escape("") == "" assert rst_escape(" foo ") == " foo " assert rst_escape(" foo ", True) == "\\ foo \\ " - assert rst_escape("\\<_>`*<_>*`\\|") == "\\\\\\<\\_\\>\\`\\*\\<\\_\\>\\*\\`\\\\|" + assert rst_escape("\\<_>`*<_>*`\\|") == "\\\\\\<\\_\\>\\`\\*\\<\\_\\>\\*\\`\\\\\\|" def test_postprocess_rst_paragraph(): From c0aca98dfc1e9b2f63c5ff88ef82ea71ec525c2f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 16 Jan 2025 19:49:02 +0100 Subject: [PATCH 3/3] Add changelog fragment. --- changelogs/fragments/65-rst-pipe.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/65-rst-pipe.yml diff --git a/changelogs/fragments/65-rst-pipe.yml b/changelogs/fragments/65-rst-pipe.yml new file mode 100644 index 0000000..ceea857 --- /dev/null +++ b/changelogs/fragments/65-rst-pipe.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Make sure to also escape pipes (``\\|``) in reStructured Text (https://github.com/ansible-community/antsibull-docs-parser/pull/65)."