mdgriffith / elm-markup / Mark.Edit

This module allows you to make edits to Parsed, that intermediate data structure we talked about in Mark.

This means you can build an editor for your document.

In order to make edits to your document you need an Id and an Edit.

Once you have those you can update your document, which can succeed or fail depending on if the edit was valid.

Updating Parsed

update : Mark.Internal.Description.Document data -> Edit -> Mark.Internal.Description.Parsed -> Result (List Mark.Error.Error) Mark.Internal.Description.Parsed


type alias Id =
Mark.Internal.Id.Id

Every block has an Id. You can retrieve the Id for a block using Mark.withId


type Edit

Text Edits

Here are edits you cna make against Mark.text and Mark.textWith blocks.

Note These edits don't apply to Mark.string. If you want to modify a Mark.string, use Mark.Edit.replace.


type alias Offset =
Basics.Int

The index of the rendered String. Let's say you have this string in your markup source.

Here is *my string*.

When you're rendering this, it's broken into three segments.

The Offset is character position where those three strings are considered as one big one.

Here are some lookups:

We're not counting control characters from our markup source.

insertText : Id -> Offset -> List Mark.New.Text -> Edit

deleteText : Id -> Offset -> Offset -> Edit


type alias Styles =
{ bold : Basics.Bool
, italic : Basics.Bool
, strike : Basics.Bool 
}

restyle : Id -> Offset -> Offset -> Styles -> Edit

Remove all styling on the text selection and replace with the given styling.

addStyles : Id -> Offset -> Offset -> Styles -> Edit

Add the given styles if they are not present in the text selection.

Note: Other styling is unaffected.

removeStyles : Id -> Offset -> Offset -> Styles -> Edit

Remove the given styles if they are present in the text selection.

Note: Other styling is unaffected.

annotate : Id -> Offset -> Offset -> String -> List ( String, Mark.New.Block ) -> Edit

Put the current text selection within an annotation with some attributes.

Here's an example that would turn the selection into a link.

Mark.Edit.annotate id
    start
    end
    "link"
    [ ( "url", Mark.New.string "https://guide.elm-lang.org/" ) ]

Note existing annotations within the selection are removed.

verbatim : Id -> Offset -> Offset -> String -> List ( String, Mark.New.Block ) -> Edit

Same as annotate, but creates a verbatim instead.

Note existing annotations within the selection are removed.

General Edits

replace : Id -> Mark.New.Block -> Edit

The Block mentioned here is actually a Mark.New.Block. Use Mark.New to create the new block you'd like.

delete : Id -> Basics.Int -> Edit

Delete a block at an index within a Mark.manyOf.

insertAt : Id -> Basics.Int -> Mark.New.Block -> Edit

Insert a block at an index within a Mark.manyOf.