Skip to content

Commit

Permalink
Merge pull request #471 from mgeisler/cross-link-word-splitter-break-…
Browse files Browse the repository at this point in the history
…words

Cross-link `break_words` with `word_splitter`
  • Loading branch information
mgeisler authored Sep 15, 2022
2 parents e5c9a76 + 29c735b commit c68d4d3
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ impl<'a> Options<'a> {
/// than `self.width` can be broken, or if they will be left
/// sticking out into the right margin.
///
/// See [`Options::word_splitter`] instead if you want to control
/// hyphenation.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -492,14 +495,31 @@ impl<'a> Options<'a> {
/// [`word_splitters::WordSplitter`] is used to fit part of a word
/// into the current line when wrapping text.
///
/// See [`Options::break_words`] instead if you want to control the
/// handling of words longer than the line width.
///
/// # Examples
///
/// ```
/// use textwrap::{Options, WordSplitter};
/// let opt = Options::new(80);
/// assert_eq!(opt.word_splitter, WordSplitter::HyphenSplitter);
/// let opt = opt.word_splitter(WordSplitter::NoHyphenation);
/// assert_eq!(opt.word_splitter, WordSplitter::NoHyphenation);
/// use textwrap::{wrap, Options, WordSplitter};
///
/// // The default is WordSplitter::HyphenSplitter.
/// let options = Options::new(5);
/// assert_eq!(wrap("foo-bar-baz", &options),
/// vec!["foo-", "bar-", "baz"]);
///
/// // The word is now so long that break_words kick in:
/// let options = Options::new(5)
/// .word_splitter(WordSplitter::NoHyphenation);
/// assert_eq!(wrap("foo-bar-baz", &options),
/// vec!["foo-b", "ar-ba", "z"]);
///
/// // If you want to breaks at all, disable both:
/// let options = Options::new(5)
/// .break_words(false)
/// .word_splitter(WordSplitter::NoHyphenation);
/// assert_eq!(wrap("foo-bar-baz", &options),
/// vec!["foo-bar-baz"]);
/// ```
///
/// [`self.word_splitter`]: #structfield.word_splitter
Expand Down

0 comments on commit c68d4d3

Please sign in to comment.