This commit is contained in:
Kovid Goyal 2025-09-28 23:11:56 +05:30
parent 80285b67f1
commit f0b79f9f64
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -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('')