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

A mark definition describes how to encode and decode a mark.

Mark


type alias MarkDefinition =
RichText.Internal.Definitions.MarkDefinition

A mark definition defines how a mark is encoded an decoded.

markDefinition : { name : String, toHtmlNode : MarkToHtml, fromHtmlNode : HtmlToMark } -> MarkDefinition

Defines a mark. The arguments are as follows:

    code : MarkDefinition
    code =
        markDefinition {name="code", toHtmlNode=codeToHtmlNode, fromHtmlNode=htmlNodeToCode}


type alias MarkToHtml =
RichText.Model.Mark.Mark -> Array RichText.Model.HtmlNode.HtmlNode -> RichText.Model.HtmlNode.HtmlNode

Type alias for a mark encoding function

codeToHtmlNode : MarkToHtml
codeToHtmlNode _ children =
    ElementNode "code" [] children


type alias HtmlToMark =
MarkDefinition -> RichText.Model.HtmlNode.HtmlNode -> Maybe ( RichText.Model.Mark.Mark
, Array RichText.Model.HtmlNode.HtmlNode 
}

Type alias for a mark decoding function

htmlNodeToCode : HtmlToMark
htmlNodeToCode definition node =
    case node of
        ElementNode name _ children ->
            if name == 'code' then
                Just ( mark def [], children )

            else
                Nothing

        _ ->
            Nothing

name : MarkDefinition -> String

Name of the mark this mark definition defines.

name code
--> "code"

toHtmlNode : MarkDefinition -> MarkToHtml

Function which encodes a mark to Html

fromHtmlNode : MarkDefinition -> HtmlToMark

Function which decodes a mark from Html

Struts

defaultMarkDefinition : String -> MarkDefinition

Creates a mark definition which assumes the name of the mark is the same as the name of the html node.

defaultMarkDefinition "b"
--> definition which encodes to <b>...</b> and decodes from "<b>...</b>"

defaultMarkToHtml : String -> RichText.Model.Mark.Mark -> Array RichText.Model.HtmlNode.HtmlNode -> RichText.Model.HtmlNode.HtmlNode

Creates an MarkToHtml function that will encode a mark to html with the same name as the mark.

defaultMarkToHtml "b"
--> returns a function which encodes to "<b>...</b>"

defaultHtmlToMark : String -> MarkDefinition -> RichText.Model.HtmlNode.HtmlNode -> Maybe ( RichText.Model.Mark.Mark, Array RichText.Model.HtmlNode.HtmlNode )

Creates an HtmlToMark function that will decode a mark from the tag name specified.

defaultHtmlToMark "b"
--> returns a function which decodes from "<b>...</b>"