From f0b79f9f64aa7b708e81bc1ab29ca5d7b16965d1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 Sep 2025 23:11:56 +0530 Subject: [PATCH] Fix #9028 --- kitty/cli.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kitty/cli.py b/kitty/cli.py index 69c4c36b9..ecccfc86a 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -472,6 +472,15 @@ def wa(text: str, indent: int = 0, leading_indent: int | None = None) -> None: print_help_for_seq = PrintHelpForSeq() +def escape_rst(text: str) -> str: + text = text.replace('\\', '\\\\') + text = text.replace('*', '\\*') + text = text.replace('`', '\\`') + text = text.replace('_', '\\_') + text = text.replace('|', '\\|') + return text + + def seq_as_rst( seq: OptionSpecSeq, usage: str | None, @@ -512,12 +521,12 @@ def seq_as_rst( a(defn + ', '.join(o + val_name for o in sorted(opt['aliases']))) if opt.get('help'): defval = opt.get('default') - t = help_text.replace('%default', str(defval)).strip() + t = help_text.replace('%default', ':code:`' + escape_rst(str(defval)) + '`').strip() t = t.replace('#placeholder_for_formatting#', '') a('') a(textwrap.indent(prettify_rst(t), ' ' * 4)) if defval is not None: - a(textwrap.indent(f'Default: :code:`{defval}`', ' ' * 4)) + a(textwrap.indent(f'Default: :code:`{escape_rst(str(defval))}`', ' ' * 4)) if opt.get('choices'): a(textwrap.indent('Choices: {}'.format(', '.join(f':code:`{c}`' for c in sorted(opt['choices']))), ' ' * 4)) a('')