Skip to content

Commit

Permalink
lame attempt at hyphenation when nbsp is present
Browse files Browse the repository at this point in the history
  • Loading branch information
ondras committed Oct 7, 2024
1 parent 1aae145 commit 619e3bc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion weasyprint/text/line_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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 +402,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 +520,8 @@ 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

0 comments on commit 619e3bc

Please sign in to comment.