Skip to content

Commit 05760c7

Browse files
authored
Merge branch 'master' into feat/pydantic
2 parents 03e2ef2 + fe2aa0e commit 05760c7

4 files changed

Lines changed: 61 additions & 4 deletions

File tree

docs/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Latest Changes
44

5+
## 0.27.1 (2026-08-03)
6+
7+
### Features
8+
9+
* ✨ Make `epilog` formatting consistent with other parts of the help string. PR [#1405](https://github.com/fastapi/typer/pull/1405) by [@svlandeg](https://github.com/svlandeg).
10+
511
### Docs
612

713
* 📝 Add Library Skills documentation. PR [#1906](https://github.com/fastapi/typer/pull/1906) by [@tiangolo](https://github.com/tiangolo).

tests/test_rich_markup_mode.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,50 @@ def test_markup_mode_default():
330330
# We're assuming the test suite is run with rich installed
331331
app = typer.Typer()
332332
assert app.rich_markup_mode == "rich"
333+
334+
335+
@pytest.mark.parametrize(
336+
"mode",
337+
["markdown", "rich", None],
338+
)
339+
def test_markup_mode_epilog(mode):
340+
app = typer.Typer(rich_markup_mode=mode)
341+
342+
help_string = "Here is a help string"
343+
344+
epilog_string = """
345+
Just wrapping up:
346+
347+
This is the first conclusion
348+
Here is conclusion two
349+
350+
That's all folks!
351+
"""
352+
353+
@app.command(help=help_string, epilog=epilog_string)
354+
def main():
355+
print("Hello World")
356+
357+
assert app.rich_markup_mode == mode
358+
359+
result = runner.invoke(app)
360+
assert "Hello World" in result.stdout
361+
362+
result = runner.invoke(app, ["--help"])
363+
result_lines = [line.strip() for line in result.stdout.split("\n")]
364+
first_index = result_lines.index("Just wrapping up:")
365+
assert first_index > 0
366+
assert result_lines[first_index + 1] == ""
367+
368+
if mode == "rich":
369+
assert result_lines[first_index + 2] == "This is the first conclusion"
370+
assert result_lines[first_index + 3] == "Here is conclusion two"
371+
assert result_lines[first_index + 4] == ""
372+
assert result_lines[first_index + 5] == "That's all folks!"
373+
else:
374+
assert (
375+
result_lines[first_index + 2]
376+
== "This is the first conclusion Here is conclusion two"
377+
)
378+
assert result_lines[first_index + 3] == ""
379+
assert result_lines[first_index + 4] == "That's all folks!"

typer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Typer, build great CLIs. Easy to code. Based on Python type hints."""
22

3-
__version__ = "0.27.0"
3+
__version__ = "0.27.1"
44

55
from shutil import get_terminal_size as get_terminal_size
66

typer/rich_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ def _get_help_text(
221221
if remaining_paragraphs:
222222
# Add a newline inbetween the header and the remaining paragraphs
223223
yield Text("")
224-
# Join with double linebreaks for markdown and Rich markup
225-
remaining_lines = "\n\n".join(remaining_paragraphs)
224+
remaining_lines = _fix_linebreaks(remaining_paragraphs, markup_mode)
226225

227226
yield _make_rich_text(
228227
text=remaining_lines,
@@ -231,6 +230,11 @@ def _get_help_text(
231230
)
232231

233232

233+
def _fix_linebreaks(paragraphs: list[str], markup_mode: MarkupModeStrict) -> str:
234+
# Join with double linebreaks for markdown and Rich markup
235+
return "\n\n".join(paragraphs)
236+
237+
234238
def _get_parameter_help(
235239
*,
236240
param: TyperOption | TyperArgument | _click.Parameter,
@@ -666,7 +670,7 @@ def rich_format_help(
666670
if obj.epilog:
667671
# Remove single linebreaks, replace double with single
668672
lines = obj.epilog.split("\n\n")
669-
epilogue = "\n".join([x.replace("\n", " ").strip() for x in lines])
673+
epilogue = _fix_linebreaks(lines, markup_mode)
670674
epilogue_text = _make_rich_text(text=epilogue, markup_mode=markup_mode)
671675
console.print(Padding(Align(epilogue_text, pad=False), 1))
672676

0 commit comments

Comments
 (0)