Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
172a489
extend test to cover issue reported in #1058
svlandeg Dec 11, 2024
9164116
set rich_markup_mode as a setting on ctx.obj to only perform escaping…
svlandeg Dec 12, 2024
c6a7347
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2024
542d6bd
deal with DefaultPlaceholder value
svlandeg Dec 12, 2024
72eb74b
add another failing test
svlandeg Dec 12, 2024
c02f0fd
Ensure that rich_to_html is only called when escaping has happened co…
svlandeg Dec 12, 2024
dd7edfd
Fix type annotation
svlandeg Dec 12, 2024
c687a85
cleanup
svlandeg Dec 12, 2024
0a9c253
small refactor
svlandeg Dec 12, 2024
860d0df
Merge branch 'master' into fix/escape
svlandeg Dec 19, 2024
be06986
Merge branch 'master' into fix/escape
svlandeg Aug 26, 2025
b6c2f8a
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] Aug 26, 2025
12a023d
refactor to avoid doing the same operations multiple times
svlandeg Aug 26, 2025
5e24bc1
fix lint issue
svlandeg Aug 26, 2025
92b0f78
Merge branch 'master' into fix/escape
svlandeg Aug 26, 2025
0a348da
use global VAR for key
svlandeg Aug 26, 2025
6d42930
fix
svlandeg Aug 26, 2025
9a502ea
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] Aug 26, 2025
c1bbfe5
Merge branch 'master' into fix/escape
svlandeg Sep 1, 2025
6354ea2
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2025
77f95dd
remove duplicate leftover from merge conflict
svlandeg Sep 1, 2025
4f7470f
follow diff more cleanly
svlandeg Sep 1, 2025
b186f2a
Merge branch 'master' into fix/escape
svlandeg Sep 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/test_rich_markup_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def main(arg: str):
assert "Hello World" in result.stdout

result = runner.invoke(app, ["--help"])
assert "ARG [required]" in result.stdout
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with master, as pointed out in #1058 (it'll have a slash)

assert all(c not in result.stdout for c in rounded)


Expand Down
5 changes: 5 additions & 0 deletions typer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ def docs(
if not typer_obj:
typer.echo("No Typer app found", err=True)
raise typer.Abort()
if hasattr(typer_obj, "rich_markup_mode"):
if not hasattr(ctx, "obj") or ctx.obj is None:
ctx.ensure_object(dict)
if isinstance(ctx.obj, dict):
ctx.obj["TYPER_RICH_MARKUP_MODE"] = typer_obj.rich_markup_mode
click_obj = typer.main.get_command(typer_obj)
docs = get_docs_for_click(obj=click_obj, ctx=ctx, name=name, title=title)
clean_docs = f"{docs.strip()}\n"
Expand Down
15 changes: 13 additions & 2 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ def get_help_record(self, ctx: click.Context) -> Optional[Tuple[str, str]]:
if extra:
extra_str = "; ".join(extra)
extra_str = f"[{extra_str}]"
if rich is not None:
rich_markup_mode = None
if hasattr(ctx, "obj") and isinstance(ctx.obj, dict):
rich_markup_mode = ctx.obj.get("TYPER_RICH_MARKUP_MODE", None)
if rich is not None and rich_markup_mode == "rich":
# This is needed for when we want to export to HTML
extra_str = rich.markup.escape(extra_str).strip()

Expand Down Expand Up @@ -565,7 +568,11 @@ def _write_opts(opts: Sequence[str]) -> str:
if extra:
extra_str = "; ".join(extra)
extra_str = f"[{extra_str}]"
if rich is not None:

rich_markup_mode = None
if hasattr(ctx, "obj") and isinstance(ctx.obj, dict):
rich_markup_mode = ctx.obj.get("TYPER_RICH_MARKUP_MODE", None)
if rich is not None and rich_markup_mode == "rich":
# This is needed for when we want to export to HTML
extra_str = rich.markup.escape(extra_str).strip()

Expand Down Expand Up @@ -690,6 +697,10 @@ def main(

def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
if not rich or self.rich_markup_mode is None:
if not hasattr(ctx, "obj") or ctx.obj is None:
ctx.ensure_object(dict)
if isinstance(ctx.obj, dict):
ctx.obj["TYPER_RICH_MARKUP_MODE"] = self.rich_markup_mode
return super().format_help(ctx, formatter)
return rich_utils.rich_format_help(
obj=self,
Expand Down
Loading