rupertlssmith / rte-toolkit-patch / RichText.Config.Spec

A spec describes what nodes and marks can be in an editor.


type Spec

A spec describes what nodes and marks can be in an editor. It's used internally to encode an editor to html, and to transform html to editor nodes. Note for the latter, the order of nodes and marks is significant, because that is the order in which each node and mark's decoder method is applied.

simpleSpec : Spec
simpleSpec =
    emptySpec
        |> withElementDefinitions
            [ codeBlock
            , crazyBlock
            , paragraph
            , image
            ]
        |> withMarkDefinitions
            [ bold
            , italic
            ]

emptySpec : Spec

An empty spec

markDefinitions : Spec -> List RichText.Internal.Definitions.MarkDefinition

list of MarkDefinition from a spec

markDefinition : String -> Spec -> Maybe RichText.Internal.Definitions.MarkDefinition

Returns the mark definition with the given name from a spec.

markDefinition "bold" markdown
--> Just (bold mark definition)

elementDefinitions : Spec -> List RichText.Internal.Definitions.ElementDefinition

list of ElementDefinition from a spec

elementDefinition : String -> Spec -> Maybe RichText.Internal.Definitions.ElementDefinition

Returns the element definition with the given name from a spec.

elementDefinition "paragraph" markdown
--> Just (paragraph element definition)

withMarkDefinitions : List RichText.Internal.Definitions.MarkDefinition -> Spec -> Spec

a spec with the given mark definitions

withElementDefinitions : List RichText.Internal.Definitions.ElementDefinition -> Spec -> Spec

a spec with the given element definitions