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, raw: String, inlines: List(Inline))
  HtmlBlock(raw: String)
  Newline
  OrderedList(
    pack: ListPack,
    items: List(ListItem),
    start: option.Option(Int),
  )
  Paragraph(raw: String, inlines: List(Inline))
  ThematicBreak
}

Constructors

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

1

Footnotes are not yet implemented

pub type Document {
  Document(
    options: Options,
    blocks: List(Block),
    links: dict.Dict(String, LinkData),
    footnotes: dict.Dict(String, FootnoteData),
  )
}

Constructors

Footnote content (not implemented)

pub type FootnoteData {
  FootnoteData(num: Int, blocks: List(Block))
}

Constructors

  • FootnoteData(num: Int, blocks: List(Block))

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)
}

Constructors

  • 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)

    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.

A link reference consists of a destination and an optional title.

pub type LinkData {
  LinkData(dest: Destination, title: option.Option(String))
}

Constructors

Represents a list item within a bullet list or ordered list.

pub type ListItem {
  ListItem(
    blocks: List(Block),
    ends_with_blank: Bool,
    contains_blank: Bool,
  )
}

Constructors

  • ListItem(
      blocks: List(Block),
      ends_with_blank: Bool,
      contains_blank: Bool,
    )

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

  • Loose

    https://spec.commonmark.org/0.31.2/#loose

  • Tight

    https://spec.commonmark.org/0.31.2/#tight

Options for parsing and HTML conversion.

pub type Options {
  Options(strip_frontmatter: Bool, footnotes: Bool)
}

Constructors

  • Options(strip_frontmatter: Bool, footnotes: Bool)

    Arguments

    strip_frontmatter

    Strip YAML frontmatter from input. (default: False)

    footnotes

    Enable footnote parsing. (default: True)

Values

pub fn lookup_footnote(
  doc: Document,
  label: String,
) -> Result(FootnoteData, Nil)

Look up information about a footnote in the document. Returns Error(Nil) if the footnote label has not been defined. Note that this lookup is by label, not by number.

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(options: Options) -> Document

Create a new empty Document structure.

pub fn new_destination(uri: String) -> Destination

Creates a link Destination from a string containing a URI.

Search Document