Skip to content

Commit

Permalink
Render option defaults as literals
Browse files Browse the repository at this point in the history
Option defaults can contain invalid characters such as backslashes.
Format them as literals to ensure they're rendered properly.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #111
  • Loading branch information
stephenfin committed Aug 17, 2022
1 parent ffceac7 commit 30516a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def _write_opts(opts: ty.List[str]) -> str:
# Starting from Click 7.0 show_default can be a string. This is
# mostly useful when the default is not a constant and
# documentation thus needs a manually written string.
extras.append(':default: %s' % opt.show_default)
extras.append(':default: ``%s``' % opt.show_default)
elif opt.default is not None and opt.show_default:
extras.append(
':default: %s'
':default: ``%s``'
% (
', '.join(str(d) for d in opt.default)
if isinstance(opt.default, (list, tuple))
Expand Down
10 changes: 5 additions & 5 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,19 @@ def foobar(bar):
.. option:: --num-param <num_param>
:default: 42
:default: ``42``
.. option:: --param <param>
:default: Something computed at runtime
:default: ``Something computed at runtime``
.. option:: --group <group>
:default: ('foo', 'bar')
:default: ``('foo', 'bar')``
.. option:: --only-show-default <only_show_default>
:default: Some default computed at runtime!
:default: ``Some default computed at runtime!``
"""
).lstrip(),
'\n'.join(output),
Expand Down Expand Up @@ -348,7 +348,7 @@ def foobar():
.. option:: --param <param>
:default: Something computed at runtime
:default: ``Something computed at runtime``
A sample epilog.
"""
Expand Down

0 comments on commit 30516a4

Please sign in to comment.