Skip to content
Myr

🐛 Fix markdown formatting in `--help` output (#815)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Garrett Smith · committed by GitHub · parent 83eaba8 · Browse files · 2 files+6 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: svlandeg <svlandeg@github.com>
  • Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
  • Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

Diff stats

2 files+6 added−9 removed

  • tests:+0 added−2 removed
  • other:+6 added−7 removed

2 files+6 added−9 removed

modified:tests/test_rich_markup_mode.py-2 removed
47 unmodified lines
48 [49 pytest.param(50 "markdown",51 ["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""],52 marks=pytest.mark.xfail,52 ),53 pytest.param(54 "rich", ["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""]55 ),
82 unmodified lines
138 "",139 "Line 3",140 "",141 ],143 marks=pytest.mark.xfail,142 ),143 pytest.param(144 "rich",145 [
141 unmodified lines
modified:typer/rich_utils.py+6 added-7 removed
188 unmodified lines
189 # Trim off anything that comes after \f on its own line190 help_text = help_text.partition("\f")[0]191192 # Get the first paragraph193 first_line = help_text.split("\n\n")[0]193 first_line, *remaining_paragraphs = help_text.split("\n\n")194195 # Remove single linebreaks196 if markup_mode != MARKUP_MODE_MARKDOWN and not first_line.startswith("\b"):197 first_line = first_line.replace("\n", " ")198 yield _make_rich_text(
1 unmodified line
200 style=STYLE_HELPTEXT_FIRST_LINE,201 markup_mode=markup_mode,202 )203203 # Add a newline inbetween the header and the remaining paragraphs204 yield Text("")205204 # Get remaining lines, remove single line breaks and format as dim207 remaining_paragraphs = help_text.split("\n\n")[1:]205 if remaining_paragraphs:209 if markup_mode != MARKUP_MODE_RICH:206 # Add a newline inbetween the header and the remaining paragraphs207 yield Text("")208 if markup_mode not in (MARKUP_MODE_RICH, MARKUP_MODE_MARKDOWN):209 # Remove single linebreaks210 remaining_paragraphs = [211 x.replace("\n", " ").strip()212 if not x.startswith("\b")
2 unmodified lines
215 ]216 # Join back together217 remaining_lines = "\n".join(remaining_paragraphs)218 else:220 # Join with double linebreaks if markdown219 # Join with double linebreaks if markdown or Rich markup220 remaining_lines = "\n\n".join(remaining_paragraphs)221222 yield _make_rich_text(223 text=remaining_lines,
521 unmodified lines