text_delta v1.1.0 TextDelta.Attributes

Attributes represent format associated with TextDelta.Operation.insert/0 or TextDelta.Operation.retain/0 operations. This library uses maps to represent attributes.

Same as TextDelta, attributes are composable and transformable. This library does not make any assumptions about attribute types, values or composition.

Summary

Types

Atom representing transformation priority. Should we prioritise left or right side?

t()

A set of attributes applicable to an operation

Functions

Composes two sets of attributes into one

Transforms right attribute set against the left one

Types

priority()
priority() :: :left | :right

Atom representing transformation priority. Should we prioritise left or right side?

t()
t() :: map

A set of attributes applicable to an operation.

Functions

compose(first, second, keep_nils \\ false)
compose(t, t, boolean) :: t

Composes two sets of attributes into one.

Simplest way to think about composing arguments is two maps being merged (in fact, that’s exactly how it is implemented at the moment).

The only thing that makes it different from standard map merge is an optional keep_nils flag. This flag controls if we want to cleanup all the null attributes before returning.

This function is used by TextDelta.compose/2.

Examples

iex> TextDelta.Attributes.compose(%{color: "blue"}, %{italic: true})
%{color: "blue", italic: true}

iex> TextDelta.Attributes.compose(%{bold: true}, %{bold: nil}, true)
%{bold: nil}

iex> TextDelta.Attributes.compose(%{bold: true}, %{bold: nil}, false)
%{}
transform(left, right, priority)
transform(t, t, priority) :: t

Transforms right attribute set against the left one.

The function also takes a third TextDelta.Attributes.priority/0 argument that indicates which set came first.

This function is used by TextDelta.transform/3.

Example

iex> TextDelta.Attributes.transform(%{italic: true},
iex>                                %{bold: true}, :left)
%{bold: true}