diff --git a/sphinx_click/ext.py b/sphinx_click/ext.py index 94bd3a7..c021f4b 100644 --- a/sphinx_click/ext.py +++ b/sphinx_click/ext.py @@ -239,11 +239,18 @@ def _format_epilog(ctx): if not ctx.command.epilog: return + bar_enabled = False for line in statemachine.string2lines( ANSI_ESC_SEQ_RE.sub('', ctx.command.epilog), 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 line yield '' diff --git a/tests/test_formatter.py b/tests/test_formatter.py index 1a80311..20a0488 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -461,6 +461,52 @@ def cli(): '\n'.join(output), ) + def test_no_line_wrapping_epilog(self): + r"""Validate behavior of the \b character in an epilog.""" + + @click.command( + epilog=""" +An epilog containing pre-wrapped text. + +\b +This is +a paragraph +without rewrapping. + +And this is a paragraph +that will be rewrapped again. +""" + ) + def foobar(): + """A sample command.""" + + ctx = click.Context(foobar, info_name='foobar') + output = list(ext._format_command(ctx, nested='short')) + + self.assertEqual( + textwrap.dedent( + """ + A sample command. + + .. program:: foobar + .. code-block:: shell + + foobar [OPTIONS] + + + An epilog containing pre-wrapped text. + + | This is + | a paragraph + | without rewrapping. + + And this is a paragraph + that will be rewrapped again. + """ + ).lstrip(), + '\n'.join(output), + ) + class NestedCommandsTestCase(unittest.TestCase): """Validate ``click.Command`` instances inside ``click.Group`` instances."""