Excribe v0.1.1 Excribe View Source

Excribe - A simple text formatting utility for Elixir.

Excribe helps you format the text in paragraph-like form. It supports word wrapping, indentation and text alignment.

Link to this section Summary

Functions

Formats the text with given options

Link to this section Types

Link to this type align_option() View Source
align_option() :: :left | :right | :center | :justify
Link to this type options() View Source
options() :: %{width: pos_integer, indent: non_neg_integer, hanging: non_neg_integer, align: align_option}

Link to this section Functions

Link to this function format(str, opts \\ %{}) View Source
format(binary, options) :: binary

Formats the text with given options.

It takes a string and a map containing valid options, transforms the given string according to the options, and returns a new string.

NOTE 1: You may get an unintended result if the original string contains non-latin characters, such as CJK characters and emojis, as they usually occupy two character cells.

NOTE 2: You may also get an unintended result if the original string contains ANSI escape characters (color, intensity, etc.). Support for ANSI strings will be added in future releases, with the help of IO.ANSI module.

Options

  • :width - Sets the maximum number of characters per line, including indentations.
  • :align - See the “Text Alignment” section below.
  • :indent and :hanging - See the “Indentation” section below.

The default option object is %{width: 80, align: :left, indent: 0, hanging: 0}.

Text Alignment

Excribe supports four text alignment options:

  • :left - Aligns the text to the left. Only one space is inserted between words, resulting in jagged right edge.
  • :right - Aligns the text to the right. Only one space is inserted between words.
  • :center - Centers the text. Only one space is inserted between words.
  • :justify - Similar to :left, but one or more spaces may be placed between words so that each line has equal width (except the last line).

Indentation

You can specify two indentation options. These options are only valid when :align is set to :left or :justify. Otherwise, they are ignored and set to zeros.

  • indent: Sets the number of spaces inserted at the beginning of the first line.
  • hanging: Sets the number of spaces inserted at the beginning of all lines except the first line. This value is relative to the left end of the screen.