From a6b5e8f1c929b78b502177315c735e3f5254a547 Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Wed, 21 Oct 2026 12:15:53 +0200 Subject: [PATCH 1/2] 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. --- src/jcloud_docsgen/core/python/_core.py | 10 +-- .../expected/user_management/service.md | 2 +- ...test_PythonModuleDocumentationGenerator.py | 12 ++-- .../core/python/_core/test__markdown_table.py | 66 +++++++++++++++++++ 4 files changed, 79 insertions(+), 11 deletions(-) diff --git a/src/jcloud_docsgen/core/python/_core.py b/src/jcloud_docsgen/core/python/_core.py index 2df4681..cfcda9a 100644 --- a/src/jcloud_docsgen/core/python/_core.py +++ b/src/jcloud_docsgen/core/python/_core.py @@ -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 ] ) diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case03/expected/user_management/service.md b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case03/expected/user_management/service.md index 1af12f0..6ce410c 100644 --- a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case03/expected/user_management/service.md +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case03/expected/user_management/service.md @@ -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` | -- | diff --git a/tests/unit/core/python/_core/test_PythonModuleDocumentationGenerator.py b/tests/unit/core/python/_core/test_PythonModuleDocumentationGenerator.py index 03921c9..e8360fa 100644 --- a/tests/unit/core/python/_core/test_PythonModuleDocumentationGenerator.py +++ b/tests/unit/core/python/_core/test_PythonModuleDocumentationGenerator.py @@ -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. | diff --git a/tests/unit/core/python/_core/test__markdown_table.py b/tests/unit/core/python/_core/test__markdown_table.py index ec0081a..4ec8e68 100644 --- a/tests/unit/core/python/_core/test__markdown_table.py +++ b/tests/unit/core/python/_core/test__markdown_table.py @@ -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 |""", ), ( [], From 3f74e6457e49601669f9a5932a257edb9e2e07c7 Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Wed, 21 Oct 2026 12:22:52 +0200 Subject: [PATCH 2/2] docs(changelog): add Markdown escape sequences entry Added a changelog entry for the escape sequences in Markdown table cells. --- docs/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5831333..8de9e79 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Fixed + +- Escape sequences for pipe characters in values of Markdown table cells + ## [0.2.2] - 2026-10-14 ### Fixed