Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "overflow-wrap: anywhere" #1520

Merged
merged 1 commit into from Dec 13, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/test_text.py
Expand Up @@ -891,6 +891,7 @@ def test_hyphenate_limit_chars_punctuation(css):

@assert_no_logs
@pytest.mark.parametrize('wrap, text, test, full_text', (
('anywhere', 'aaaaaaaa', lambda a: a > 1, 'aaaaaaaa'),
('break-word', 'aaaaaaaa', lambda a: a > 1, 'aaaaaaaa'),
('normal', 'aaaaaaaa', lambda a: a == 1, 'aaaaaaaa'),
('break-word', 'hyphenations', lambda a: a > 3,
Expand Down Expand Up @@ -920,6 +921,32 @@ def test_overflow_wrap(wrap, text, test, full_text):
assert full_text == lines_full_text


@assert_no_logs
@pytest.mark.parametrize('wrap, text, body_width, expected_width', (
('anywhere', 'aaaaaa', 10, 20),
('anywhere', 'aaaaaa', 40, 40),
('break-word', 'aaaaaa', 40, 100),
('normal', 'aaaaaa', 40, 100),
))
def test_overflow_wrap_2(wrap, text, body_width, expected_width):
page, = render_pages('''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
body {width: %dpx; font-family: weasyprint; font-size: 20px; }
table {overflow-wrap: %s; white-space: normal; }
</style>
<table><tr><td>%s
''' % (body_width, wrap, text))
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
tr, = row_group.children
td, = tr.children
assert td.width == expected_width


def white_space_lines(width, space):
page, = render_pages('''
<style>
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/css/validation/properties.py
Expand Up @@ -1176,7 +1176,7 @@ def white_space(keyword):
@single_keyword
def overflow_wrap(keyword):
"""``overflow-wrap`` property validation."""
return keyword in ('normal', 'break-word')
return keyword in ('anywhere', 'normal', 'break-word')


@property()
Expand Down
3 changes: 2 additions & 1 deletion weasyprint/text/line_break.py
Expand Up @@ -536,7 +536,8 @@ def split_first_line(text, style, context, max_width, justification_spacing,
first_line_width, _ = line_size(first_line, style)
space = max_width - first_line_width
# If we can break words and the first line is too long
if not minimum and overflow_wrap == 'break-word' and space < 0:
if space < 0 and (overflow_wrap == 'anywhere' or
(overflow_wrap == 'break-word' and not minimum)):
# Is it really OK to remove hyphenation for word-break ?
hyphenated = False
# TODO: Modify code to preserve W3C condition:
Expand Down