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

Hyphenation: consider words that contain a NBSP #2271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion weasyprint/text/line_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .ffi import FROM_UNITS, TO_UNITS, ffi, gobject, pango, pangoft2, unicode_to_char_p
from .fonts import font_features, get_font_description

NBSP = '\u00a0'

def line_size(line, style):
"""Get logical width and height of the given ``line``.
Expand Down Expand Up @@ -400,7 +401,7 @@ def split_first_line(text, style, context, max_width, justification_spacing,
dictionary = pyphen.Pyphen(lang=lang, left=left, right=right)
context.dictionaries[dictionary_key] = dictionary
dictionary_iterations = [
start for start, end in dictionary.iterate(next_word)]
start for start, end in dictionary.iterate(next_word) if start[-1] != NBSP]
else:
dictionary_iterations = []

Expand Down Expand Up @@ -518,6 +519,9 @@ def get_next_word_boundaries(text, lang):
return None
bytestring, log_attrs = get_log_attrs(text, lang)
for i, attr in enumerate(log_attrs):
follows_nbsp = (i < len(text) and text[i] == NBSP)
if follows_nbsp:
continue
if attr.is_word_end:
word_end = i
break
Expand Down