This package picks (close to) optimal points to break a paragraph into lines.
Based on the paper Bridging the Algorithm Gap: A Linear-time Functional Program for Paragraph Formatting
{ maximumWidth : Basics.Int
, optimalWidth : Basics.Int
, stringWidth : String -> Basics.Int
}
Formatting options
String.length
usually gives good results, but other options (based on a font, or something creative) can be used as well.Note: if a word is longer than the maximum width of a line it is left as-is. The line is broken after the word.
format : Options -> String -> String
Format a string using the given options
The output is one string where the lines are broken with newline \n
characters.
lines : Options -> String -> List String
Format a string using the given options, returning the individual lines