Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/65-rst-pipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "Make sure to also escape pipes (``\\|``) in reStructured Text (https://github.com/ansible-community/antsibull-docs-parser/pull/65)."
1 change: 1 addition & 0 deletions src/antsibull_docs_parser/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
14 changes: 14 additions & 0 deletions test-vectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
<p>Use <code class='docutils literal notranslate'>0</code>|<code class='docutils literal notranslate'>1</code>.</p>
html_plain: |-
<p>Use <code>0</code>|<code>1</code>.</p>
md: |-
Use <code>0</code>\|<code>1</code>\.
rst: |-
Use :literal:`0`\ \|\ :literal:`1`.
rst_plain: |-
Use :literal:`0`\ \|\ :literal:`1`.
ansible_doc_text: |-
Use `0'|`1'.
2 changes: 1 addition & 1 deletion tests/unit/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading