pub fn unfill(text: &str) -> (String, Options<'_>)Expand description
Unpack a paragraph of already-wrapped text.
This function attempts to recover the original text from a single
paragraph of wrapped text, such as what fill() would produce.
This means that it turns
textwrap: a small
library for
wrapping text.back into
textwrap: a small library for wrapping text.In addition, it will recognize a common prefix and a common line ending among the lines.
The prefix of the first line is returned in
Options::initial_indent and the prefix (if any) of the the
other lines is returned in Options::subsequent_indent.
Line ending is returned in Options::line_ending. If line ending
can not be confidently detected (mixed or no line endings in the
input), LineEnding::LF will be returned.
In addition to ' ', the prefixes can consist of characters used
for unordered lists ('-', '+', and '*') and block quotes
('>') in Markdown as well as characters often used for inline
comments ('#' and '/').
The text must come from a single wrapped paragraph. This means
that there can be no empty lines ("\n\n" or "\r\n\r\n") within
the text. It is unspecified what happens if unfill is called on
more than one paragraph of text.
ยงExamples
use textwrap::{LineEnding, unfill};
let (text, options) = unfill("\
* This is an
example of
a list item.
");
assert_eq!(text, "This is an example of a list item.\n");
assert_eq!(options.initial_indent, "* ");
assert_eq!(options.subsequent_indent, " ");
assert_eq!(options.line_ending, LineEnding::LF);