A mark definition describes how to encode and decode a mark.
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:
name
- The unique name for this mark. This should be something like 'bold' or 'link'.
toHtmlNode
- The function that converts the mark to html. This is used in rendering,
DOM validation, and path translation.
fromHtmlNode
- The function that converts html to marks. This is used in things
like paste to determine the editor nodes from html.
code : MarkDefinition
code =
markDefinition {name="code", toHtmlNode=codeToHtmlNode, fromHtmlNode=htmlNodeToCode}
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
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
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>"