@ende/markdown/types

ende add jsr:@ende/markdown

Version 2026.10.18 on JSR.

Types for the Markdown syntax tree. The node names and fields follow mdast, including its GitHub Flavored Markdown nodes (tables, delete and footnotes), with these differences: link reference definitions are resolved into the Link and Image nodes that use them (so there are no definition, linkReference or imageReference nodes), nodes have no position, a Heading has an id, and GitHub alerts are Admonition nodes.

import type { Heading, Root } from "@ende/markdown/types";
import { parse } from "@ende/markdown/parse";
import { assertEquals } from "@ende/assert";

const root: Root = parse("# Hi");
const heading = root.children[0] as Heading;
assertEquals(heading.depth, 1);

Exports

  • Admonition — A GitHub alert, such as `> [!NOTE]`. Only parsed with the `gfm` option, from a block quote at the top level of the document whose first line is just the marker (`[!NOTE]`, `[!TIP]`, `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]`, in any case) and that has content after it. The marker line isn't part of the children.
  • AlignType — The alignment of a table column: `:--` is `"left"`, `--:` is `"right"`, `:-:` is `"center"`, and `---` is `null`.
  • BlockContent — Nodes that can appear in a block container (Root, Blockquote, ListItem or FootnoteDefinition).
  • Blockquote — A block quote.
  • Break — A hard line break: two or more spaces, or a backslash, before a newline.
  • Code — A fenced or indented code block.
  • DefinitionContent — Definitions, which can appear in a block container next to BlockContent. Link reference definitions are resolved while parsing, so the only definition in the tree is FootnoteDefinition.
  • Delete — Strikethrough text, such as `~~this~~`. Only parsed with the `gfm` option.
  • Emphasis — Emphasis, such as `*this*`.
  • FootnoteDefinition — A footnote definition, such as `[^1]: The note.`. Only parsed with the `gfm` option. The definition stays where it was written; `render()` moves the definitions that are referenced into a footnotes section at the end.
  • FootnoteReference — A reference to a footnote, such as `[^1]`. Only parsed with the `gfm` option, and only when a FootnoteDefinition with the same identifier exists; otherwise the text stays as it is.
  • Heading — An ATX (`# Title`) or setext (`Title` underlined with `=` or `-`) heading.
  • Html — Raw HTML. As a child of a block container it's an HTML block; inside a paragraph or other phrasing content it's inline HTML.
  • Image — An image. Like Link, reference images are resolved.
  • InlineCode — A code span, such as `` `code` ``.
  • Link — A link. Inline links, autolinks, and reference links all become this node; a reference link carries the URL and title of its definition.
  • List — A bullet or ordered list.
  • ListItem — A list item.
  • Literal — Nodes that have a string `value`.
  • Nodes — Any node, as a union discriminated by `type`.
  • Paragraph — A paragraph.
  • Parent — Nodes that have children.
  • ParseOptions — Options for `parse()`.
  • PhrasingContent — Nodes that can appear in paragraphs, headings and other inline content.
  • RenderOptions — Options for `render()`.
  • Root — The root of a document.
  • Strong — Strong emphasis, such as `**this**`.
  • Table — A table. Only parsed with the `gfm` option. The first row is the header row, and every row has one cell per column.
  • TableCell — A cell of a TableRow.
  • TableRow — A row of a Table.
  • Text — Plain text.
  • ThematicBreak — A thematic break, such as `***` or `---`.
  • TocEntry — A heading in the list `toc()` returns.
  • TocOptions — Options for `toc()`.