lerzegov/elm-markup/1.0.0

Renamed to lerzegov/elm-markup-fork. It is published under that name, and new versions come out there.

Versions published as lerzegov/elm-markup still install under that name. 1 version could not be recovered and cannot be installed.

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: no fork with tag 1.0.0 found (28 same-name repos checked); https://github.com/lerzegov/elm-markup-fork has tag 1.0.0, but not a package Elm could build from it; https://github.com/lerzegov/elm-markup-fork commit 1ea589d5d7f182e39d0a124ab1561a7e076e4f31 (the tag's commit when Software Heritage visited) has tag 1.0.0, but not a package Elm could build from it; no cached copy. Use another version.

Details

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 : Document meta data -> Edit -> Parsed -> Result (List Error) Parsed
type alias 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 can 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 =
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.

  • Here is
  • my string (which is bold)
  • .

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

Here are some lookups:

  • 0 -> H
  • 8 -> m
  • 17 -> .

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

insertString : Id -> Offset -> String -> Edit

This will work on both styled text and string datatypes.

insertText : Id -> Offset -> List Text -> Edit
deleteText : Id -> Offset -> Offset -> Edit
type alias Styles =
{ bold : Bool
, italic : Bool
, strike : 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, 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, Block ) -> Edit

Same as annotate, but creates a verbatim instead.

Note existing annotations within the selection are removed.

General Edits

replace : Id -> Block -> Edit

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

delete : List Id -> Edit

Delete blocks.

This may fail if the block cannot be deleted(such as a field in a record).

insertAfter : Id -> List Block -> Edit

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

insertFirst : Id -> Block -> Edit

Insert a block at the first position.

The id needed here is of the parent.

Reading

copy : List Id -> Parsed -> List Block
copyText : Id -> Offset -> Offset -> Parsed -> List Text