Skip to content

Commit 6649ae5

Browse files
authored
RST: also escape | (#65)
* Add test for before-case. * Escape '|' in RST. * Add changelog fragment.
1 parent 97ee012 commit 6649ae5

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- "Make sure to also escape pipes (``\\|``) in reStructured Text (https://github.com/ansible-community/antsibull-docs-parser/pull/65)."

src/antsibull_docs_parser/rst.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def rst_escape(
3232
value = value.replace("_", "\\_")
3333
value = value.replace("*", "\\*")
3434
value = value.replace("`", "\\`")
35+
value = value.replace("|", "\\|")
3536

3637
# RST does not like it when the inside of `...` starts or ends with a whitespace
3738
# (here, all kind of whitespaces count, not just spaces...)

test-vectors.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,3 +1621,17 @@ test_vectors:
16211621
-------------
16221622
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]]
16231623
  `  '`  '*    *`    '
1624+
pipe_symbol:
1625+
source: Use C(0)|C(1).
1626+
html: |-
1627+
<p>Use <code class='docutils literal notranslate'>0</code>|<code class='docutils literal notranslate'>1</code>.</p>
1628+
html_plain: |-
1629+
<p>Use <code>0</code>|<code>1</code>.</p>
1630+
md: |-
1631+
Use <code>0</code>\|<code>1</code>\.
1632+
rst: |-
1633+
Use :literal:`0`\ \|\ :literal:`1`.
1634+
rst_plain: |-
1635+
Use :literal:`0`\ \|\ :literal:`1`.
1636+
ansible_doc_text: |-
1637+
Use `0'|`1'.

tests/unit/test_rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_rst_escape():
1717
assert rst_escape("") == ""
1818
assert rst_escape(" foo ") == " foo "
1919
assert rst_escape(" foo ", True) == "\\ foo \\ "
20-
assert rst_escape("\\<_>`*<_>*`\\") == "\\\\\\<\\_\\>\\`\\*\\<\\_\\>\\*\\`\\\\"
20+
assert rst_escape("\\<_>`*<_>*`\\|") == "\\\\\\<\\_\\>\\`\\*\\<\\_\\>\\*\\`\\\\\\|"
2121

2222

2323
def test_postprocess_rst_paragraph():

0 commit comments

Comments
 (0)