diff --git a/src/rendering/line_iter.rs b/src/rendering/line_iter.rs index c2de8850..9b947026 100644 --- a/src/rendering/line_iter.rs +++ b/src/rendering/line_iter.rs @@ -422,31 +422,30 @@ where fn process_word( &mut self, handler: &mut E, - w: &str, + mut w: &str, ) -> Result<(), E::Error> { - match w.char_indices().find(|(_, c)| *c == SPEC_CHAR_NBSP) { - Some((space_pos, _)) => { - // If we have anything before the space... - if space_pos != 0 { - let word = unsafe { - // Safety: space_pos must be a character boundary - w.get_unchecked(0..space_pos) - }; - handler.printed_characters(word, None)?; - } + loop { + let mut iter = w.char_indices(); + match iter.find(|(_, c)| *c == SPEC_CHAR_NBSP) { + Some((space_pos, _)) => { + // If we have anything before the space... + if space_pos != 0 { + let word = unsafe { + // Safety: space_pos must be a character boundary + w.get_unchecked(0..space_pos) + }; + handler.printed_characters(word, None)?; + } - handler.whitespace("\u{a0}", 1, self.spaces.consume(1))?; + handler.whitespace("\u{a0}", 1, self.spaces.consume(1))?; - // If we have anything after the space... - if let Some(word) = w.get(space_pos + SPEC_CHAR_NBSP.len_utf8()..) { - return self.process_word(handler, word); + // If we have anything after the space... + w = iter.as_str(); } - } - None => handler.printed_characters(w, None)?, + None => return handler.printed_characters(w, None), + } } - - Ok(()) } fn should_draw_whitespace(&self, handler: &E) -> bool {