Skip to content

Commit 4d1cfd2

Browse files
gar1tsvlandegtiangolo
authored
🐛 Fix markdown formatting in --help output (#815)
Co-authored-by: svlandeg <[email protected]> Co-authored-by: Sofie Van Landeghem <[email protected]> Co-authored-by: Sebastián Ramírez <[email protected]>
1 parent 83eaba8 commit 4d1cfd2

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

tests/test_rich_markup_mode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def main(arg: str):
4949
pytest.param(
5050
"markdown",
5151
["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""],
52-
marks=pytest.mark.xfail,
5352
),
5453
pytest.param(
5554
"rich", ["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""]
@@ -140,7 +139,6 @@ def main(arg: str):
140139
"Line 3",
141140
"",
142141
],
143-
marks=pytest.mark.xfail,
144142
),
145143
pytest.param(
146144
"rich",

typer/rich_utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def _get_help_text(
190190
help_text = help_text.partition("\f")[0]
191191

192192
# Get the first paragraph
193-
first_line = help_text.split("\n\n")[0]
193+
first_line, *remaining_paragraphs = help_text.split("\n\n")
194+
194195
# Remove single linebreaks
195196
if markup_mode != MARKUP_MODE_MARKDOWN and not first_line.startswith("\b"):
196197
first_line = first_line.replace("\n", " ")
@@ -200,13 +201,11 @@ def _get_help_text(
200201
markup_mode=markup_mode,
201202
)
202203

203-
# Add a newline inbetween the header and the remaining paragraphs
204-
yield Text("")
205-
206204
# Get remaining lines, remove single line breaks and format as dim
207-
remaining_paragraphs = help_text.split("\n\n")[1:]
208205
if remaining_paragraphs:
209-
if markup_mode != MARKUP_MODE_RICH:
206+
# Add a newline inbetween the header and the remaining paragraphs
207+
yield Text("")
208+
if markup_mode not in (MARKUP_MODE_RICH, MARKUP_MODE_MARKDOWN):
210209
# Remove single linebreaks
211210
remaining_paragraphs = [
212211
x.replace("\n", " ").strip()
@@ -217,7 +216,7 @@ def _get_help_text(
217216
# Join back together
218217
remaining_lines = "\n".join(remaining_paragraphs)
219218
else:
220-
# Join with double linebreaks if markdown
219+
# Join with double linebreaks if markdown or Rich markup
221220
remaining_lines = "\n\n".join(remaining_paragraphs)
222221

223222
yield _make_rich_text(

0 commit comments

Comments
 (0)