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)." 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 9019874..37c6167 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..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():