Skip to content

Commit

Permalink
Extend pre-wrapped text support to options
Browse files Browse the repository at this point in the history
Seems click will let you use the '\b' character in help text for options
also.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #106
  • Loading branch information
stephenfin committed Jun 20, 2022
1 parent 011a998 commit fdea9dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ def _format_option(opt: click.Option) -> ty.Generator[str, None, None]:
yield '.. option:: {}'.format(opt_help[0])
if opt_help[1]:
yield ''
bar_enabled = False
for line in statemachine.string2lines(
ANSI_ESC_SEQ_RE.sub('', opt_help[1]), tab_width=4, convert_whitespace=True
):
if line == '\b':
bar_enabled = True
continue
if line == '':
bar_enabled = False
line = '| ' + line if bar_enabled else line
yield _indent(line)


Expand Down
26 changes: 26 additions & 0 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ def test_no_line_wrapping(self):
that will be rewrapped again.
"""
)
@click.option(
'--param',
help="""An option containing pre-wrapped text.
\b
This is
a paragraph
without rewrapping.
And this is a paragraph
that will be rewrapped again.
""",
)
def cli():
"""A command containing pre-wrapped text.
Expand Down Expand Up @@ -457,6 +470,19 @@ def cli():
cli [OPTIONS]
.. rubric:: Options
.. option:: --param <param>
An option containing pre-wrapped text.
| This is
| a paragraph
| without rewrapping.
And this is a paragraph
that will be rewrapped again.
An epilog containing pre-wrapped text.
| This is
Expand Down

0 comments on commit fdea9dd

Please sign in to comment.