commonmark/ast

This module defines the Markdown AST used.

This AST can be used to manipulate markdown documents or render them with your own algorithm.

CommonMark defines two major types of elements which have a hierarchical relationship:

Types

Block nodes are used to define the overall structure of a document.

pub type BlockNode {
  HorizontalBreak
  Heading(level: Int, contents: List(InlineNode))
  CodeBlock(
    info: Option(String),
    full_info: Option(String),
    contents: String,
  )
  HtmlBlock(html: String)
  Paragraph(contents: List(InlineNode))
  BlockQuote(contents: List(BlockNode))
  OrderedList(
    contents: List(ListItem),
    start: Int,
    marker: OrderedListMarker,
  )
  UnorderedList(
    contents: List(ListItem),
    marker: UnorderedListMarker,
  )
}

Constructors

  • HorizontalBreak
  • Heading(level: Int, contents: List(InlineNode))
  • CodeBlock(
      info: Option(String),
      full_info: Option(String),
      contents: String,
    )
  • HtmlBlock(html: String)
  • Paragraph(contents: List(InlineNode))
  • BlockQuote(contents: List(BlockNode))
  • OrderedList(
      contents: List(ListItem),
      start: Int,
      marker: OrderedListMarker,
    )
  • UnorderedList(
      contents: List(ListItem),
      marker: UnorderedListMarker,
    )

Documents contain all the information necessary to render a document, both structural and metadata.

pub type Document {
  Document(
    blocks: List(BlockNode),
    references: Dict(String, Reference),
  )
}

Constructors

  • Document(
      blocks: List(BlockNode),
      references: Dict(String, Reference),
    )
pub type EmphasisMarker {
  AsteriskEmphasisMarker
  UnderscoreEmphasisMarker
}

Constructors

  • AsteriskEmphasisMarker
  • UnderscoreEmphasisMarker

Inline nodes are used to define the formatting and individual elements that appear in a document.

pub type InlineNode {
  CodeSpan(contents: String)
  Emphasis(contents: List(InlineNode), marker: EmphasisMarker)
  StrongEmphasis(
    contents: List(InlineNode),
    marker: EmphasisMarker,
  )
  StrikeThrough(contents: List(InlineNode))
  Link(
    contents: List(InlineNode),
    title: Option(String),
    href: String,
  )
  ReferenceLink(contents: List(InlineNode), ref: String)
  Image(title: Option(String), href: String)
  UriAutolink(href: String)
  EmailAutolink(href: String)
  HtmlInline(html: String)
  Text(contents: String)
  HardLineBreak
  SoftLineBreak
  NamedEntity(name: String, codepoint: List(UtfCodepoint))
  NumericCharacterReference(codepoint: UtfCodepoint, hex: Bool)
}

Constructors

  • CodeSpan(contents: String)
  • Emphasis(contents: List(InlineNode), marker: EmphasisMarker)
  • StrongEmphasis(
      contents: List(InlineNode),
      marker: EmphasisMarker,
    )
  • StrikeThrough(contents: List(InlineNode))
  • Link(
      contents: List(InlineNode),
      title: Option(String),
      href: String,
    )
  • ReferenceLink(contents: List(InlineNode), ref: String)
  • Image(title: Option(String), href: String)
  • UriAutolink(href: String)
  • EmailAutolink(href: String)
  • HtmlInline(html: String)
  • Text(contents: String)

    Text content shouldn’t contain line breaks. See HardLineBreak and SoftLineBreak for the canonical representation of line breaks that renderers can make decisions about.

  • HardLineBreak
  • SoftLineBreak
  • NamedEntity(name: String, codepoint: List(UtfCodepoint))

    A named HTML entity. The CommonMark spec calls for these to be rendered into unicode instead of as HTML entities. Equivalent to "&" <> name <> ";" in HTML.

  • NumericCharacterReference(codepoint: UtfCodepoint, hex: Bool)

    Numeric character entity. The CommonMark spec calls for these to be rendered into unicode instead of as HTML entities. Equivalent to "&" <> int.to_string(codepoint) <> ";" in HTML.

pub type ListItem {
  ListItem(contents: List(BlockNode))
}

Constructors

  • ListItem(contents: List(BlockNode))
pub type OrderedListMarker {
  PeriodListMarker
  BracketListMarker
}

Constructors

  • PeriodListMarker

    The list used a . as the marker for the ordered list

  • BracketListMarker

    The list used a ) as the marker for the ordered list

A reference used with ReferenceLink nodes

pub type Reference {
  Reference(href: String, title: Option(String))
}

Constructors

  • Reference(href: String, title: Option(String))
pub type UnorderedListMarker {
  DashListMarker
  PlusListMarker
  AsteriskListMarker
}

Constructors

  • DashListMarker

    The list used a - as the marker for the unordered list

  • PlusListMarker

    The list used a + as the marker for the unordered list

  • AsteriskListMarker

    The list used a * as the marker for the unordered list

Search Document