mweiss/elm-rte-toolkit/1.0.4

RichText.Model.Mark

A mark is a piece of information that can be attached to an inline node (like color, font, and link information).

Mark

type alias Mark =
Mark

A mark is a piece of information defined by a MarkDefinition that can be attached to an inline node, like color font, or link information.

mark : MarkDefinition -> List Attribute -> Mark

Creates a mark. The arguments are as follows:

  • definition is the MarkDefinition that defines this node. Note that even though marks require a mark definition, it's still safe to use (==) because the function arguments are not stored on the Mark

  • attributes are a list of attributes, for example [StringAttribute 'href' 'www.google.com']

    mark link [StringAttribute 'href' 'www.google.com']
    --> creates a link mark
name : Mark -> String

Name of the mark

attributes : Mark -> List Attribute

A list of attributes associated with the mark

withAttributes : List Attribute -> Mark -> Mark

Creates a mark with new attributes

Mark order

A mark order is a way of sorting marks. In order to have a single way of representing a document, it's necessary to make sure marks are sorted in a consistent way. Mark orders should be derived from the spec.

markOrderFromSpec spec
--> returns a mark order that can be used to sort a list of marks

Derives the mark order from the order of the spec's mark definitions, e.g. (markDefinitions spec).

spec : Spec
spec =
    emptySpec
        |> withMarkDefinitions
            [ link
            , bold
            , italic
            , code
            ]


markOrderFromSpec spec
--> returns a mark order that will sort marks in the following order:  link, bold, italic, and code.

List helpers

sort : MarkOrder -> List Mark -> List Mark

Sorts a list of marks from the given MarkOrder

spec : Spec
spec =
    emptySpec
        |> withMarkDefinitions
            [ bold
            , italic
            ]


sort (markOrderFromSpec spec) [mark italic [], mark bold []]
--> [mark bold [], mark italic []]
= Add
| Remove
| Flip

Actions used to toggle a mark from a list of marks.

  • Add adds or replaces a mark if it exists.

  • Remove removes all marks with the same name if it exists.

  • Flip will remove a mark if a mark with the same name exists, otherwise it will add it.

toggle : ToggleAction -> MarkOrder -> Mark -> List Mark -> List Mark

Returns a list that executes the toggle action and maintains the given mark order.

-- Assuming the mark order is bold < italic < code:
toggle Add (markOrderFromSpec spec) (mark code []) [mark bold [], mark italic []]
--> [mark bold [], mark italic [], mark code []]
hasMarkWithName : String -> List Mark -> Bool

Predicate that returns true if the list of marks contains a mark with the given name