Skip to content

Commit

Permalink
remove yielding of additional newline after first_line if it's markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Aug 30, 2024
1 parent 8dd3b5b commit 66cd2f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 8 additions & 6 deletions tests/test_rich_markup_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def main(arg: str):
@pytest.mark.parametrize(
"mode,lines",
[
("markdown", ["First line", "", "Line 1", "", "Line 2", ""]),
("rich", ["First line", "", "Line 1", "", "Line 2", ""]),
("none", ["First line", "", "Line 1", "Line 2", ""]),
("markdown", ["First line", "Line 1", "", "Line 2", "", "Line 3", ""]),
("rich", ["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""]),
("none", ["First line", "", "Line 1", "Line 2", "Line 3", ""]),
],
)
def test_markup_mode_newline_pr815(mode: str, lines: List[str]):
Expand All @@ -61,6 +61,8 @@ def main(arg: str):
Line 1
Line 2
Line 3
"""
print(f"Hello {arg}")

Expand All @@ -81,7 +83,7 @@ def main(arg: str):
@pytest.mark.parametrize(
"mode,lines",
[
("markdown", ["First line", "", "Line 1 Line 2 Line 3", ""]),
("markdown", ["First line", "Line 1 Line 2 Line 3", ""]),
("rich", ["First line", "", "Line 1", "Line 2", "Line 3", ""]),
("none", ["First line", "", "Line 1 Line 2 Line 3", ""]),
],
Expand Down Expand Up @@ -116,7 +118,7 @@ def main(arg: str):
@pytest.mark.parametrize(
"mode,lines",
[
("markdown", ["First line", "", "", "• 1", "• 2", "• 3", ""]),
("markdown", ["First line", "", "• 1", "• 2", "• 3", ""]),
("rich", ["First line", "", "- 1", "- 2", "- 3", ""]),
("none", ["First line", "", "- 1 - 2 - 3", ""]),
],
Expand Down Expand Up @@ -151,7 +153,7 @@ def main(arg: str):
@pytest.mark.parametrize(
"mode,lines",
[
("markdown", ["First line", "", "", "• 1", "• 2", "• a", "• b", "• 3", ""]),
("markdown", ["First line", "", "• 1", "• 2", "• a", "• b", "• 3", ""]),
("rich", ["First line", "", "- 1", "- 2", "- a", "- b", "- 3", ""]),
("none", ["First line", "", "- 1 - 2 - a - b - 3", ""]),
],
Expand Down
5 changes: 3 additions & 2 deletions typer/rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def _get_help_text(

# Get remaining lines, remove single line breaks and format as dim
if remaining_paragraphs:
yield Text("")
if markup_mode not in MARKUP_MODE_MARKDOWN:
yield Text("")
if markup_mode not in (MARKUP_MODE_RICH, MARKUP_MODE_MARKDOWN):
# Remove single linebreaks
remaining_paragraphs = [
Expand All @@ -215,7 +216,7 @@ def _get_help_text(
# Join back together
remaining_lines = "\n".join(remaining_paragraphs)
else:
# Join with double linebreaks if markdown
# Join with double linebreaks if markdown or Rich markup
remaining_lines = "\n\n".join(remaining_paragraphs)

yield _make_rich_text(
Expand Down

0 comments on commit 66cd2f8

Please sign in to comment.