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.
Search the AST for nodes whose label contains the given string, returning the Id of the first node found, if any.
Create a sourceMap from the AST: a dictionary whose keys are text strings and whose values ids of the corresponding elements in the DOM
Get lead ing text element from AST
An MDBlock (Markdown block) carries
- the type of the block
- its level
- its unparsed contentAn MBlockWithId is like na MDBlock, except that it has an
Id : (Int, Int)which should be thought of as
( elementId, version )where the id is unique to each block.
The type of a parsed Block
Used to generate Ids of Html elements and to implement differential rendering. An Id has the form
(elementId, version) : (Int, Int
The elementId is a an integer representing position in a traversal of the tree of blocks obtained by parsing the text. The version number is incremented after each edit.
Given a string s, return (ss, id), where ss is a string containing s and id a Maybe value representing the id of the corresponding element in the rendered text.
Compute id from a string representation of that id, e.g..
idFromString "i5v3"
--> (5,3)Compute a string representation of an id. Thus
stringFromId (5,3)
-> "i5v3"Return the id of a block
Scan the tree, incrementing the version of the target Id if found. This function is used to update the AST int order to highlight the rendered text which belongs to the target Id. Use
Markdown.Render.fromASTWithOptions
markdownOption
outputOption
targetId
astCheck for equality of
- blockType
- level
- contentignoring the id.
Return true of the blocks have the same id
Project an MDBlockWithId to an MDBlock by omitting its id
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.
Parse a string using a Markdown flavor option, returning the AST. Example: