folkertdev / elm-paragraph / Paragraph

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


type alias Options =
{ maximumWidth : Basics.Int
, optimalWidth : Basics.Int
, stringWidth : String -> Basics.Int 
}

Formatting options

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