text_delta v1.4.0 TextDelta.Document View Source

Document-related logic like splitting it into lines etc.

Link to this section Summary

Types

Reason for an error

Line segments

Result of getting document lines

Functions

Breaks document into multiple line segments

Breaks document into multiple line segments

Link to this section Types

Link to this type error_reason() View Source
error_reason() :: :bad_document

Reason for an error.

Line segments.

Each line has a delta of the content on that line (minus ) and a set of attributes applied to the entire block.

Link to this type lines_result() View Source
lines_result() :: {:ok, line_segments()} | {:error, error_reason()}

Result of getting document lines.

An ok/error tuple. Represents either a successful retrieval in form of {:ok, [line]} or an error in form of {:error, reason}.

Link to this section Functions

Breaks document into multiple line segments.

Given document will be split according to newline characters ().

Examples

successful application:

iex> doc =
iex>  TextDelta.new()
iex>  |> TextDelta.insert("hi\nworld")
iex>  |> TextDelta.insert("\n", %{header: 1})
iex> TextDelta.lines(doc)
{:ok, [ {%TextDelta{ops: [%{insert: "hi"}]}, %{}},
        {%TextDelta{ops: [%{insert: "world"}]}, %{header: 1}} ]}

error handling:

iex> doc = TextDelta.retain(TextDelta.new(), 3)
iex> TextDelta.lines(doc)
{:error, :bad_document}

Breaks document into multiple line segments.

Equivalent to &TextDelta.Document.lines/1, but instead of returning ok/error tuples raises a RuntimeError.