ProsemirrorEx.Model.Mark (prosemirror_ex v0.3.0)

Copy Markdown View Source

A mark is a piece of information that can be attached to a node, such as it being emphasized, in code font, or a link. It has a type and optionally a set of attributes that provide further information (such as the target of the link). Marks are created through a Schema, which controls which types exist and which attributes they have.

Summary

Functions

Add this mark to the given set, replacing any marks of the same type that exist in it, and sorting it to match the order of marks in the schema. Returns the input set when this mark is already in it.

Test whether this mark has the same type and attributes as another mark.

Deserialize a mark from its JSON representation.

Test whether this mark is in the given set of marks. Returns true/false (matching JS Mark.prototype.isInSet).

The empty set of marks.

Remove this mark from the given set, returning the set itself if it isn't found in it.

Test whether two sets of marks are identical.

Create a properly sorted mark set from null, a single mark, or an unsorted array of marks.

Serialize this mark to JSON.

Types

t()

@type t() :: %ProsemirrorEx.Model.Mark{
  attrs: map(),
  type: ProsemirrorEx.Model.MarkType.t()
}

Functions

add_to_set(mark, set)

@spec add_to_set(t(), [t()]) :: [t()]

Add this mark to the given set, replacing any marks of the same type that exist in it, and sorting it to match the order of marks in the schema. Returns the input set when this mark is already in it.

Faithful port of the JS addToSet method.

eq(mark1, mark2)

@spec eq(t(), t()) :: boolean()

Test whether this mark has the same type and attributes as another mark.

from_json(schema, json)

Deserialize a mark from its JSON representation.

Takes a schema and a JSON map with "type" and optionally "attrs" keys.

is_in_set(mark, set)

@spec is_in_set(t(), [t()]) :: boolean()

Test whether this mark is in the given set of marks. Returns true/false (matching JS Mark.prototype.isInSet).

none()

@spec none() :: [t()]

The empty set of marks.

remove_from_set(mark, set)

@spec remove_from_set(t(), [t()]) :: [t()]

Remove this mark from the given set, returning the set itself if it isn't found in it.

same_set(a, b)

@spec same_set([t()], [t()]) :: boolean()

Test whether two sets of marks are identical.

set_from(marks)

@spec set_from([t()] | t() | nil) :: [t()]

Create a properly sorted mark set from null, a single mark, or an unsorted array of marks.

to_json(mark)

@spec to_json(t()) :: map()

Serialize this mark to JSON.