Extract the content from a MarkdownOutput value
When there is no interaction between the Markdown text and and an
on-the-fly editor, use the withSimpleOptions function:
withSimpleOptions :
MarkdownOption
-> OutputOption
-> String
-> MarkdownOutputFor example:
withSimpleOptions Extended Basic "This is *italic text.*"
|> content
|> Html.map MarkdownMsgwhere one has
import Markdown.Render exposing(withSimpleOptions, MarkdownMsg(..))
import Markdown.Options expsosing(..)
type Msg = MarkdownMsg MarkdownMsg | ...Use the withOptions and withOptionsFromAST functions if you need
more control over the editing process (see the ./Editor folder
for examples).
The function parse yields a syntax tree (AST: abstract syntax tree). The functions renderHtml,
renderHtmlWithTOC, and renderHtmlWithExternaTOC render the
AST in various forms, as described below.
This library
The idea of the optimizations used in app-demo-optimized
(see the repo)
is to parse the document text when the
document is first opened. The resulting parse
tree is stored as
model.lastAst. Each block in the AST carries
a label (version, id): (Int, Int), where
the id is unique to each block.
Each time the text changes, a new AST is computed
with an incremented version number. The
function Diff.mergeWith equals is applied to
the old and new ASTs
to compute an updated AST. The updated AST
is identical to the new AST except for the id's.
The id of a node in the updated AST is
the same as in the old AST if and only if the type, level,
and content of the node has not changed.
This information is used to signal MathJax not
to re-render mathematical text that is unchanged.
To see where these optimizations are applied,
look for the places in app-demo-optimized/Main.elm
where functions in the modules
ParseWithId and Markdown.ElmWithId are called.
The kinds of Markdown output
The type of a composite document
Parse the input and render it to Html, e.g.,
toHtml ExtendedMath "Pythagoras said: $a^2 + b^2 c^2$."Render source text
Render from an AST
Render source text with simplified opptions
Extract the content from a MarkdownOutput value
Extract the title from a MarkdownOutput value
Extract the table of contents from a MarkdownOutput value
Render a parse tree to Html.
Parse the input and render it to Html, e.g.,
toHtmlWithId ( 0, 0 ) 0 ExtendedMath "Pythagoras said: $a^2 + b^2 c^2$."Count the number of display math element blocks in the parse tree
Use
Html MarkdownMsgso that user clicks on elements in the rendered text can be detected.