def words(text_elements): word = elements.word() for element in text_elements: if isinstance(element, xsc.Text): mystyle = None element = [ element, ] else: mystyle = style(element) for child in element: for (syllable, starts_word, ends_word,) in syllables( child, mystyle): if starts_word and len(word) > 0: word[-1]._whitespace_style = syllable._style yield word word = elements.word() word.append(syllable) if ends_word: yield word word = elements.word() if len(word) > 0: yield word
def words(bits): """ Yields elements.word instances for each of the white-space separated words in bits. """ word = elements.word() for letters, ends_in_whitespace, style, whitespace_style in bits: for part in syllable_parts(letters): word.append(elements.syllable(part, style, whitespace_style)) if ends_in_whitespace: yield word word = elements.word() if len(word) > 0: yield word