fix: #20 Enhance CLI help text formatting and documentation #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix line break preservation in CLI help text with pretty formatting
Summary
This PR fixes an issue where line breaks in CLI help text and docstrings weren't being preserved when using the
prettyformatting option. Previously, the parser was stripping empty lines and concatenating description text without maintaining the original formatting, which caused multi-line help messages to appear as single paragraphs.Problem
When parsing markdown content in the
prettymodule, the code was:line.strip()This resulted in CLI documentation that didn't match the intended formatting, making help text harder to read.
Solution
Modified the
parse_markdown_to_treefunction insrc/mkdocs_typer2/pretty.pyto:lines[j].strip()tolines[j]to maintain empty lines.rstrip()when joining lines to remove trailing whitespace while keeping leading formattingChanges Made
src/mkdocs_typer2/pretty.py: Updated parsing logic to preserve line breaks in descriptionssrc/mkdocs_typer2/cli.py: Added multi-line help message example for testingtests/test_pretty.py: Added test case to verify line break preservationCHANGELOG.md: Documented the bug fixTesting
Added a new test case
test_parse_markdown_with_line_breaks()that verifies:Impact
This fix ensures that CLI documentation generated with the
prettyoption maintains the intended formatting and readability of help text, making it easier for users to understand command usage and options.Example
Before: Multi-line help text would appear as a single paragraph
After: Line breaks are preserved, maintaining the original formatting and readability
No breaking changes introduced - this is purely a bug fix that improves the user experience.