Skip to main content

rewrite

Function rewrite 

Source
pub fn rewrite(paragraph: &Element, edited: &str) -> Vec<Element>
Expand description

What a paragraph becomes when its whole text is replaced by what an editor hands back: one paragraph, or several where the new text holds newlines the old one did not.

The old and the new text are compared from both ends, and only the middle they differ in is replaced, so spans and markers outside it are untouched and a marker inside it stays where it was. A newline inside that middle is a paragraph break: the paragraph is split there, each half with the original’s style, and the newline itself is not kept. A newline outside it is a text:line-break the editor was shown and left alone.