jxxcarlson/elm-markdown/2.4.0

NOTE: the latest version is 10.1.0

ParseWithId

The purpose of this module is to parse a Document, that is, a string, into an abstract syntax tree (AST) which can then be further transformed or passed on to a rendering function. The AST is a rose tree of MDBlockWithId — short for "Markdown Blocks."

See the documentation at the head of module Markdown.ElmWithId for the rationale for this module.

toMDBlockTree : Int -> Option -> Document -> Tree MDBlockWithId

Parse a string using a Markdown flavor option, returning the AST. Example:

ParseWithId.toMDBlockTree 1 Extended "This **is** a test."
--> Tree (MDBlockWithId (0,1)
-->    (MarkdownBlock Root) 0 (M (Paragraph [
-->       Line [OrdinaryText "DOCUMENT"]]))) [
-->          Tree (MDBlockWithId (1,1)
-->            (MarkdownBlock Plain) 1 (M (Paragraph [
-->                Line [  OrdinaryText ("This ")
-->              , BoldText ("is ")
-->              , OrdinaryText ("a test.")]
-->              , Line []
-->            ])))
-->      []]
--> : Tree.Tree ParseWithId.MDBlockWithId
type MDBlock
= MDBlock BlockType Level BlockContent

An MDBlock (Markdown block) carries

- the type of the block
- its level
- its unparsed content
= MDBlockWithId Id BlockType Level BlockContent

An MBlockWithId is like na MDBlock, except that it has an

Id : (Int, Int)

which should be thought of as

(version, id)

where the id is unique to each block.

| T String

The type of a parsed Block

Check for equality of

- blockType
- level
- content

ignoring the id.

Project an MDBlockWithId to an MDBlock by omitting its id

stringOfId : Id -> String

Return a string value of and Id

Return the id of a block

Return a string representing the content of a block if it is of type T. Otherwise, return the empty string.

A string representation of an MDBlockTree. Useful for verifying the validity of the AST.