Text.Format.Para
Description
A paragraph formatting utility. Provided with input text that is arbitrarily split amongst several strings, this utility will reformat the text into paragraphs which do not exceed the specified width. Paragraphs are delimited by blank lines in the input.
This function is roughly equivalent to the Unix fmt
utility.
Features:
- An indentation/prefix text may be specified. This prefix is used on the first paragraph line and determines the standard indentation for all subsequent lines. If no indentation is specified, the blank indentation of the first line of the first paragraph becomes the default indentation for all paragraphs.
- Subsequent paragraphs may increase their indentation over the default as determined by the indentation level of their first line. Indentation values less than that of the primary paragraph are ignored.
- Paragraph text is reformatted to fit the paragraph layout.
- Extra whitespace is removed.
- "French spacing" is used: if the current word is capitalized and the previous word ended in a punctuation character, then two spaces are used between the words instead of a single space which is the default elsewhere.
- Avoids orphan words. The last line of a paragraph will usually be formatted to contain at least 2 words, pulling from the line above it.
- Recognizes lists of items, where each item starts with * or - or alphanumeric characters followed by a ) or . character. Uses list-oriented per-item indentation independent of paragraph indentation.
Documentation
Arguments
:: Int | Width |
-> Maybe String | Prefix (defines indent), Nothing means indent is taken from first input line |
-> [String] | Text to format in arbitrarily-divided strings. Blank lines separate paragraphs. Paragraphs are indented the same as the first line if second argument is Nothing. |
-> [String] | Formatted text |
The formatParas
function accepts an arbitrarily-divided list of
Strings along with a width and optional indentation/prefix and
returns an array of strings representing paragraphs formatted to
fit the specified width and indentation.