mork/document
Types
Block level elements like HR tags, headings, code blocks and paragraphs.
pub type Block {
BlockQuote(blocks: List(Block))
BulletList(pack: ListPack, items: List(ListItem))
Code(lang: option.Option(String), text: String)
Empty
Heading(level: Int, text: List(Inline))
HtmlBlock(raw: String)
Newline
OrderedList(
pack: ListPack,
items: List(ListItem),
start: option.Option(Int),
)
Paragraph(text: List(Inline))
ThematicBreak
}
Constructors
-
BlockQuote(blocks: List(Block)) -
-
Code(lang: option.Option(String), text: String) -
Empty -
Heading(level: Int, text: List(Inline)) -
HtmlBlock(raw: String) -
Newline -
OrderedList( pack: ListPack, items: List(ListItem), start: option.Option(Int), ) -
Paragraph(text: List(Inline)) -
ThematicBreak
Link destination - Currently classified as Absolute, Relative or Anchor, but this is not really used for anything at the moment.
pub type Destination {
Absolute(uri: String)
Relative(uri: String)
Anchor(id: String)
}
Constructors
-
Absolute(uri: String) -
Relative(uri: String) -
Anchor(id: String)
The root of a parsed Markdown document Contains the Block structure, the list of link references and footnotes1
Footnotes are not yet implemented
pub type Document {
Document(
blocks: List(Block),
links: dict.Dict(String, LinkData),
footnotes: dict.Dict(String, FootnoteData),
)
}
Constructors
-
Document( blocks: List(Block), links: dict.Dict(String, LinkData), footnotes: dict.Dict(String, FootnoteData), )Creates a new Document structure.
Inline elements contained within a block.
pub type Inline {
Autolink(uri: String)
CodeSpan(String)
EmailAutolink(mail: String)
Emphasis(List(Inline))
Footnote(num: Int, label: String)
FullImage(text: List(Inline), data: LinkData)
FullLink(text: List(Inline), data: LinkData)
HardBreak
InlineFootnote(num: Int, text: List(Inline))
InlineHtml(
tag: String,
attrs: dict.Dict(String, String),
children: List(Inline),
)
RawHtml(String)
RefImage(text: List(Inline), label: String)
RefLink(text: List(Inline), label: String)
SoftBreak
Strong(List(Inline))
Text(String)
Delim(style: String, len: Int, can_open: Bool, can_close: Bool)
UnparsedInline(String)
}
Constructors
-
Autolink(uri: String) -
CodeSpan(String) -
EmailAutolink(mail: String) -
Emphasis(List(Inline)) -
Footnote(num: Int, label: String) -
-
-
HardBreak -
InlineFootnote(num: Int, text: List(Inline)) -
-
RawHtml(String) -
RefImage(text: List(Inline), label: String) -
RefLink(text: List(Inline), label: String) -
SoftBreak -
Strong(List(Inline)) -
Text(String) -
Delim(style: String, len: Int, can_open: Bool, can_close: Bool)Delimiters are consecutive runs of * or _, which are first parsed into Delim elements and then resolved into the correct Emphasis, Strong or literal Text in a second pass.
-
UnparsedInline(String)Parsing is performed in two phases: During block parsing, the inline contents are stored in an UnparsedInline element which is later parsed into the correct elements. This is because we need to parse the entire document once to find all link references before parsing inline content.
A link reference consists of a destination and an optional title.
pub type LinkData {
LinkData(dest: Destination, title: option.Option(String))
}
Constructors
-
LinkData(dest: Destination, title: option.Option(String))
A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight. (The difference in HTML output is that paragraphs in a loose list are wrapped in
tags, while paragraphs in a tight list are not.)
pub type ListPack {
Loose
Tight
}
Constructors
-
Loosehttps://spec.commonmark.org/0.31.2/#loose
-
Tighthttps://spec.commonmark.org/0.31.2/#tight
Values
pub fn lookup_link(
doc: Document,
label: String,
) -> Result(LinkData, Nil)
Look up information about a link in the document. Returns Error(Nil) if the link label has not been defined.
pub fn new_destination(uri: String) -> Destination
Creates a link Destination from a string containing a URI.