mdgriffith/elm-markup/3.0.1

Mark.New

Create a new Mark.Block that can be added to your document using Mark.Edit.replace or Mark.Edit.insertAt.

Let's say we are capturing a basic diagram in our document and we want to dynamically insert a circle.

We can make a new circle by writing the following function

import Mark.New as New


type alias Circle =
    { x : Int
    , y : Int
    , label : String
    }


circle : Circle -> Mark.New.Block
circle details =
    New.record "Circle"
        [ ( "label", New.string details.label )
        , ( "x", New.int details.x )
        , ( "y", New.int details.y )
        ]

And then insert our newly made circle using Mark.Edit.insertAt.

Note: The document will only accept edits which are valid.

type alias Block =
Expectation

Primitives

string : String -> Block
int : Int -> Block
float : Float -> Block
bool : Bool -> Block

Blocks

block : String -> Block -> Block
record : String -> List ( String, Block ) -> Block
many : List Block -> Block
tree : List Tree -> Block
type Tree
= Tree
{ icon : Icon
, content : List Block
, children : List Tree
}
type Icon
= Bullet
| Number

Text

Here's an example of creating some text.

newText =
    New.text
        [ Mark.unstyled "Look at my "
        , Mark.bold "cool"
        , Mark.unstyled " new text!"
        ]
type alias Text =
InlineExpectation
text : List Text -> Block
unstyled : String -> Text
bold : String -> Text
italics : String -> Text
strike : String -> Text
type alias Styles =
{ bold : Bool
, italic : Bool
, strike : Bool
}
styled : Styles -> String -> Text

Text Annotation

{ name : String
, text : List ( Styles, String )
, fields : List ( String, Block )
}
-> Text
New.annotation
    { name = "link"
    , text =
        [ New.unstyled "my link to the elm website!" ]
    , fields =
        [ ( "url", Mark.string "https://elm-lang.com" ) ]
    }
{ name : String
, text : String
, fields : List ( String, Block )
}
-> Text