rupertlssmith / rte-toolkit-patch / 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 =
RichText.Internal.Definitions.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 : RichText.Internal.Definitions.MarkDefinition -> List RichText.Model.Attribute.Attribute -> Mark

Creates a mark. The arguments are as follows:

    mark link [StringAttribute 'href' 'www.google.com']
    --> creates a link mark

name : Mark -> String

Name of the mark

attributes : Mark -> List RichText.Model.Attribute.Attribute

A list of attributes associated with the mark

withAttributes : List RichText.Model.Attribute.Attribute -> Mark -> Mark

Creates a mark with new attributes

Mark order


type MarkOrder

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

markOrderFromSpec : RichText.Config.Spec.Spec -> MarkOrder

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 []]


type ToggleAction
    = Add
    | Remove
    | Flip

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

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 -> Basics.Bool

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