diff --git a/.coverage b/.coverage index 0e8b572..f9303bc 100644 Binary files a/.coverage and b/.coverage differ diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3f0a8..605cb88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Fixed +- Fixed issue where line breaks in help text weren't preserved when using `pretty` formatting option +- Line breaks in CLI help messages and docstrings are now properly rendered in the generated documentation + ## [0.1.4] - 2025-03-15 ### Added diff --git a/coverage.xml b/coverage.xml new file mode 100644 index 0000000..443b8a9 --- /dev/null +++ b/coverage.xml @@ -0,0 +1,265 @@ + + + + + + /Users/taylorroberts/GitHub/syn54x/mkdocs-typer2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mkdocs_typer2/cli.py b/src/mkdocs_typer2/cli.py index ecd8c55..f723eb6 100644 --- a/src/mkdocs_typer2/cli.py +++ b/src/mkdocs_typer2/cli.py @@ -2,7 +2,7 @@ import typer -app = typer.Typer(help="A sample CLI") +app = typer.Typer(help="A sample CLI\n\nThis is a multi-line help message.") @app.command() diff --git a/src/mkdocs_typer2/pretty.py b/src/mkdocs_typer2/pretty.py index da80b9f..44a592a 100644 --- a/src/mkdocs_typer2/pretty.py +++ b/src/mkdocs_typer2/pretty.py @@ -57,11 +57,12 @@ def parse_markdown_to_tree(content: str) -> CommandNode: and not lines[j].startswith("**") and not lines[j].startswith("```") ): - if lines[j].strip(): # Only add non-empty lines - desc_lines.append(lines[j].strip()) + # Preserve the original line content, including empty lines for line breaks + desc_lines.append(lines[j]) j += 1 if desc_lines: + # Join with newlines to preserve line breaks, then strip trailing whitespace root.description = "\n".join(desc_lines) break @@ -97,13 +98,14 @@ def parse_markdown_to_tree(content: str) -> CommandNode: and i > 0 ): # We're in description mode and not at a section marker yet - if line.strip(): # Only add non-empty lines - desc_lines.append(line.strip()) + # Preserve the original line content, including empty lines for line breaks + desc_lines.append(line) elif line.startswith("```console"): # Usage section - end of description if in_description and desc_lines: - current_command.description = "\n".join(desc_lines) + # Join with newlines to preserve line breaks, then strip trailing whitespace + current_command.description = "\n".join(desc_lines).rstrip() in_description = False in_commands_section = False # Find the line with usage example @@ -116,7 +118,8 @@ def parse_markdown_to_tree(content: str) -> CommandNode: elif line.startswith("**Arguments**:"): # End of description section if in_description and desc_lines: - current_command.description = "\n".join(desc_lines) + # Join with newlines to preserve line breaks, then strip trailing whitespace + current_command.description = "\n".join(desc_lines).rstrip() in_description = False current_section = "arguments" in_commands_section = False @@ -124,7 +127,8 @@ def parse_markdown_to_tree(content: str) -> CommandNode: elif line.startswith("**Options**:"): # End of description section if in_description and desc_lines: - current_command.description = "\n".join(desc_lines) + # Join with newlines to preserve line breaks, then strip trailing whitespace + current_command.description = "\n".join(desc_lines).rstrip() in_description = False current_section = "options" in_commands_section = False @@ -132,7 +136,8 @@ def parse_markdown_to_tree(content: str) -> CommandNode: elif line.startswith("**Commands**:"): # End of description section, start commands section if in_description and desc_lines: - current_command.description = "\n".join(desc_lines) + # Join with newlines to preserve line breaks, then strip trailing whitespace + current_command.description = "\n".join(desc_lines).rstrip() in_description = False current_section = None in_commands_section = True diff --git a/tests/test_pretty.py b/tests/test_pretty.py index a8ac4f5..2e9b4b2 100644 --- a/tests/test_pretty.py +++ b/tests/test_pretty.py @@ -280,6 +280,36 @@ def test_tree_to_markdown_with_commands(): def test_tree_to_markdown_no_commands(): - cmd = CommandNode(name="mycli", description="A test CLI", commands=[]) - markdown = tree_to_markdown(cmd) - assert "*No commands available*" in markdown + """Test that commands table shows 'No commands available' when empty.""" + cmd = CommandNode(name="test", commands=[]) + result = tree_to_markdown(cmd) + assert "*No commands available*" in result + + +def test_parse_markdown_with_line_breaks(): + """Test that line breaks in help text are preserved.""" + markdown = """# mycli + +A test CLI tool + +This is a multi-line help message. + +```console +$ mycli --help +``` + +**Arguments**: +* `name`: The name argument [required] + +**Options**: +* `--verbose`: Enable verbose mode +""" + tree = parse_markdown_to_tree(markdown) + + # Check that line breaks are preserved in the description + assert tree.name == "mycli" + assert "A test CLI tool" in tree.description + assert "This is a multi-line help message." in tree.description + # Verify there's a line break between the two lines + assert "\n" in tree.description + assert tree.description.count("\n") >= 1