fix(markdown): escape pipe characters in table cells

Pipe characters ('|') in Markdown table cells are now replaced with an
escape sequence ('\|') to ensure that cells are not split by Markdown
renderers.

Tests which expected pipe characters to be unescaped, which is
incorrect, were updatedto expect an escape sequence and new test cases
to ensure the correct escaping behavior were added.
This commit is contained in:
jakob.scheid committed 2026-10-21 12:15:53 +02:00
1 parent a85cd1b433
commit a6b5e8f1c9
4 files changed
+79 -11

No files matched your search

+6 -4
View File
@@ -263,11 +263,13 @@ def _markdown_table(
'| '
+ ' | '.join(
[
str(col if col is not None else missing_value).replace(
'\n', ' '
)
str(col if col is not None else missing_value)
.replace('\n', ' ')
.replace('|', '\\|')
if one_line_values
else str(col if col is not None else missing_value)
else str(
col if col is not None else missing_value
).replace('|', '\\|')
for col in row
]
)
@@ -47,7 +47,7 @@ Return type: `User`
| `user_id` | `str` | normal | -- | -- |
| `name` | `str` | normal | -- | -- |
| `email` | `str` | normal | -- | -- |
| `age` | `int | None` | normal | `None` | -- |
| `age` | `int \| None` | normal | `None` | -- |
@@ -250,8 +250,8 @@ Return type: `int | float`
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int | float` | normal | -- | The first number. |
| `b` | `int | float` | normal | -- | The second number. |
| `a` | `int \\| float` | normal | -- | The first number. |
| `b` | `int \\| float` | normal | -- | The second number. |
@@ -461,8 +461,8 @@ Return type: `int | float`
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int | float` | normal | -- | The first number. |
| `b` | `int | float` | normal | -- | The second number. |
| `a` | `int \\| float` | normal | -- | The first number. |
| `b` | `int \\| float` | normal | -- | The second number. |
@@ -672,8 +672,8 @@ Return type: `int | float`
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int | float` | normal | -- | The first number. |
| `b` | `int | float` | normal | -- | The second number. |
| `a` | `int \\| float` | normal | -- | The first number. |
| `b` | `int \\| float` | normal | -- | The second number. |
@@ -138,6 +138,72 @@ from src.jcloud_docsgen.core.python._core import _markdown_table
"""| a |
| --- |
| line1\nline2 |""",
),
(
['a'],
[('line1\nline2 | 2',)],
True,
False,
False,
'--',
"""| a |
| --- |
| line1\nline2 \\| 2 |""",
),
(
['a'],
[('line1\nline2 | 2',)],
True,
False,
True,
'--',
"""| a |
| --- |
| line1 line2 \\| 2 |""",
),
(
['a'],
[('1 | 2',)],
True,
False,
True,
'--',
"""| a |
| --- |
| 1 \\| 2 |""",
),
(
['a'],
[('1 |',)],
True,
False,
True,
'--',
"""| a |
| --- |
| 1 \\| |""",
),
(
['a'],
[('|',)],
True,
False,
True,
'--',
"""| a |
| --- |
| \\| |""",
),
(
['a'],
[('| 2',)],
True,
False,
True,
'--',
"""| a |
| --- |
| \\| 2 |""",
),
(
[],