Skip to content

Conversation

@Ox54
Copy link
Contributor

@Ox54 Ox54 commented Sep 1, 2025

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 pretty formatting 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 pretty module, the code was:

  • Stripping empty lines from descriptions using line.strip()
  • Only adding non-empty lines to description arrays
  • Losing the visual structure and readability of multi-line help messages

This resulted in CLI documentation that didn't match the intended formatting, making help text harder to read.

Solution

Modified the parse_markdown_to_tree function in src/mkdocs_typer2/pretty.py to:

  1. Preserve original line content: Changed from lines[j].strip() to lines[j] to maintain empty lines
  2. Maintain line breaks: Keep empty lines in description arrays to preserve paragraph structure
  3. Clean trailing whitespace: Use .rstrip() when joining lines to remove trailing whitespace while keeping leading formatting

Changes Made

  • src/mkdocs_typer2/pretty.py: Updated parsing logic to preserve line breaks in descriptions
  • src/mkdocs_typer2/cli.py: Added multi-line help message example for testing
  • tests/test_pretty.py: Added test case to verify line break preservation
  • CHANGELOG.md: Documented the bug fix

Testing

Added a new test case test_parse_markdown_with_line_breaks() that verifies:

  • Multi-line descriptions are parsed correctly
  • Line breaks are preserved between description paragraphs
  • The resulting tree structure maintains the original formatting

Impact

This fix ensures that CLI documentation generated with the pretty option 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.

- Updated the CLI help message to support multi-line descriptions.
- Improved the `parse_markdown_to_tree` function to preserve line breaks in help text.
- Added tests to ensure line breaks are correctly handled in the documentation output.
- Updated CHANGELOG to reflect these changes.
@Ox54 Ox54 self-assigned this Sep 1, 2025
@Ox54 Ox54 added the bug Something isn't working label Sep 1, 2025
@codecov
Copy link

codecov bot commented Sep 1, 2025

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mkdocs_typer2/pretty.py 50.00% 3 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #21      +/-   ##
==========================================
- Coverage   95.57%   95.53%   -0.04%     
==========================================
  Files           5        5              
  Lines         226      224       -2     
==========================================
- Hits          216      214       -2     
  Misses         10       10              
Files with missing lines Coverage Δ
src/mkdocs_typer2/cli.py 100.00% <100.00%> (ø)
src/mkdocs_typer2/pretty.py 94.55% <50.00%> (-0.08%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ded5eb2...cc4dfd5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ox54 Ox54 merged commit 117b7b0 into main Sep 1, 2025
3 of 4 checks passed
@Ox54 Ox54 deleted the Ox54/issue20 branch September 1, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Help text does not to include linebreaks (\n)

2 participants