Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mkdocs_click/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def _make_description(ctx: click.Context, remove_ascii_art: bool = False) -> Ite
# https://github.com/pallets/click/pull/2151
help_string = inspect.cleandoc(help_string)

# Skip rest of the description if the `\f` marker is found as per Click's documentation.
# https://click.palletsprojects.com/en/stable/documentation/#truncating-help-texts
help_string = help_string.partition("\f")[0]

if not remove_ascii_art:
yield from help_string.splitlines()
yield ""
Expand Down
31 changes: 31 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ def hello_escape_marker():
"""


@click.command()
@click.option("-d", "--debug", help="Include debug output")
def hello_truncating_escape_marker():
"""
Hello, world!\f

Hidden world.
"""


@click.command()
@click.option("-d", "--debug", help="Include debug output")
def hello_truncating_escape_marker_on_new_line():
"""
Hello, world!
\f

Hidden world.
"""


@click.command()
@click.option("-d", "--debug", help="Include debug output")
def hello_ascii_art():
Expand Down Expand Up @@ -114,6 +135,16 @@ def test_basic_escape_marker():
assert output == HELLO_EXPECTED


def test_truncating_escape_marker():
output = "\n".join(make_command_docs("hello", hello_truncating_escape_marker))
assert output == HELLO_EXPECTED


def test_truncating_escape_marker_on_new_line():
output = "\n".join(make_command_docs("hello", hello_truncating_escape_marker_on_new_line))
assert output == HELLO_EXPECTED


def test_basic_ascii_art():
output = "\n".join(make_command_docs("hello", hello_ascii_art, remove_ascii_art=True))
assert output == HELLO_EXPECTED
Expand Down