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 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 |""", ), ( [],