diff --git a/gapic/utils/lines.py b/gapic/utils/lines.py index 58e5978b2e..e0261d5b44 100644 --- a/gapic/utils/lines.py +++ b/gapic/utils/lines.py @@ -78,6 +78,8 @@ def wrap(text: str, width: int, *, offset: int = None, indent: int = 0) -> str: # Break off the first line of the string to address non-zero offsets. first = text.split('\n')[0] + '\n' if len(first) > width - offset: + # Ensure `break_on_hyphens` is set to `False` when using + # `textwrap.wrap` to avoid breaking hyperlinks with hyphens. initial = textwrap.wrap(first, break_long_words=False, width=width - offset, diff --git a/tests/unit/utils/test_lines.py b/tests/unit/utils/test_lines.py index 65df6f1c36..6d39d2c9f6 100644 --- a/tests/unit/utils/test_lines.py +++ b/tests/unit/utils/test_lines.py @@ -87,3 +87,6 @@ def test_wrap_indent_short(): def test_wrap_short_line_preserved(): assert lines.wrap('foo\nbar\nbaz', width=80) == 'foo\nbar\nbaz' + +def test_wrap_does_not_break_hyphenated_word(): + assert lines.wrap('do-not-break', width=5) == 'do-not-break'