Valkyrian Labs

API Reference

Reference exports, options, renderer props, directive names, and default theme names.

API Reference

Package Exports

Main export:

1import {2  DEFAULT_CALLOUT_THEMES,3  DEFAULT_CARD_THEMES,4  DEFAULT_CARDS_THEMES,5  DEFAULT_CELL_THEMES,6  DEFAULT_CODE_LANGS,7  DEFAULT_COLUMNS_THEMES,8  DEFAULT_DETAILS_THEMES,9  DEFAULT_DOCS_TABLE_THEMES,10  DEFAULT_ENTRY_THEMES,11  DEFAULT_EXCHANGE_THEMES,12  DEFAULT_SECTION_THEMES,13  DEFAULT_STEPS_THEMES,14  DEFAULT_TAB_THEMES,15  DEFAULT_TABS_THEMES,16  DEFAULT_TOC_THEMES,17  MarkdownBlock,18  markdownField,19  payloadMarkdown,20} from 'payload-markdown'

Server export:

1import {2  MarkdownBlockComponent,3  MarkdownRenderer,4  PayloadMarkdownField,5} from 'payload-markdown/server'

Client export ('use client' components for bundled apps):

1import {2  MarkdownRendererClient,3  PayloadMarkdownField,4} from 'payload-markdown/client'

PayloadMarkdownField is the same component as the server export's PayloadMarkdownField. Fields created by markdownField() use the admin component path <package>/server#PayloadMarkdownField, where <package> is the name you installed (payload-markdown or @valkyrianlabs/payload-markdown), so existing import maps for the scoped package do not change; <package>/client#PayloadMarkdownField resolves to the same component. MarkdownRendererClient adds tab, code-copy and reference-table behavior (disclosure, expand and collapse all, filter, deep links, copy-link buttons) to HTML rendered with renderMarkdown(): render it with containerId set to the id of the element that contains the HTML. Reference tables with collapsed rows need it and the stylesheet, as tabs do; see Reference Tables.

MCP export (server-only, for @payloadcms/plugin-mcp and custom agents):

1import {2  getMarkdownGuide,3  MarkdownAgentError,4  payloadMarkdownMcpPrompts,5  payloadMarkdownMcpTools,6  publishMarkdown,7  readMarkdownDocuments,8  validateMarkdown,9  withPayloadMarkdownMcp,10  writeMarkdown,11} from 'payload-markdown/mcp'

See AI Agents and MCP, the MCP tools reference and Custom Agents.

The server and client exports require a bundler (they import CSS and React client code). The main, render and advanced exports load in plain Node.

Headless render export (no React, Next.js or CSS; works in plain Node):

1import {2  compileMarkdown,3  createHeadingSlugger,4  extractHeadingAnchors,5  getDirectiveSpec,6  readPayloadMarkdownSettings,7  renderMarkdown,8  slugifyHeading,9} from 'payload-markdown/render'

Directive spec (generated from the directive registry at build time; the same data getDirectiveSpec() returns; getDirectiveSpec({ docs, directives }) adds a site's kinds and presets):

1import spec from 'payload-markdown/directive-spec.json' with { type: 'json' }

The spec lists every directive (kind, open and close markers, [label] attribute; forms and leaf for a directive that also has a one-line form, openAttributes when any attribute is accepted), its attributes with a type (url, enum, string, boolean or number) and an optional format (icon, palette, kind), allowed values and theme group, the built-in theme names, badge types and targets, tab-value and heading-slug rules, parser constraints, docsTable (reference-table kinds, row and id rules, the binding grammar and diagnostics), inline (the inline roles, their recognition rules, :ref matching and the :fact grammar), codeFences (the fence meta grammar and the terminal rules), usage (the synopsis grammar, option links and output), exchange (panes, badges and diagnostics), and related, index and tabs.sync (their rules and diagnostics). specVersion changes only when the JSON shape changes; readers must ignore keys, format values and optional fields they do not know (notes in the spec says so too).

Reference-table vectors (Markdown inputs with the tables, rows, bindings, entries and diagnostics the renderer extracts, and inlineFacts for documents with :fact roles; the native pmdocs tool and the skills' checker are tested against them):

1import vectors from 'payload-markdown/docs-table-vectors.json' with { type: 'json' }

Stylesheet export:

1import 'payload-markdown/styles.css'

Advanced export:

1import {2  createHeadingSlugger,3  createPayloadMarkdownIconRegistryEntry,4  createPayloadMarkdownIconRegistrySource,5  extractHeadingAnchors,6  slugifyHeading,7  vlMdCodeBlockConfig,8  vlMdConfig,9  vlMdTailwindField,10} from 'payload-markdown/advanced'

renderMarkdown

1function renderMarkdown(markdown: string, config?: RenderMarkdownConfig): Promise<RenderedMarkdown>2 3type RenderMarkdownConfig = MarkdownRenderConfig & {4  collectionSlug?: string5  scope?: 'blocks' | 'field'6  // settings object, Payload config or Payload instance; false: no plugin defaults7  settings?: PayloadMarkdownSettingsSource | false | null8}9 10type RenderedMarkdown = {11  diagnostics: RenderDiagnostic[]12  entries: DocEntry[]13  errors: string[]14  headings: Array<{ depth: number; id: string; text: string }>15  html: string16  links: Array<{ kind: 'definition' | 'directive' | 'image' | 'link'; url: string }>17  text: string18  warnings: string[]19}20 21type RenderDiagnostic = {22  code?: string23  column?: number24  line?: number25  message: string26  severity: 'error' | 'info' | 'warning'27  // config: a problem with the render configuration (e.g. a directive preset), repeated on every render28  source: 'code' | 'config' | 'directive' | 'icon' | 'render' | 'theme'29}

Like MarkdownRenderer, renderMarkdown applies the plugin defaults for scope (default field) and collectionSlug from settings, or from the process-wide settings registry when settings is omitted. readPayloadMarkdownSettings(source) returns the settings stored on a Payload config or instance.

links lists authored URLs before sanitization; unsafe directive links are removed from html and reported in diagnostics.

Reference Entries

entries lists the rows of every docs-table and every standalone :::entry: tables in the order they start in the source, each table's rows in tree order. id is the exact row id in html, so it is safe to link to.

1type DocEntry = {2  id: string3  name: string4  path: string[]5  depth: number6  kind: string7  key: string // the binding key: path with <…> positionals removed8  fields: Record<string, string> // as authored; absent fields are left out9  values: Record<string, string> // comparable values of the fields10  summary?: string11  fact?: string // explicit binding, resolved against the table's from12  parent?: string // the parent row's id13  line?: number14  synthetic?: true // a tree parent the table did not write15  table?: { caption?: string; from?: string; id?: string; kind: string }16}

A :since[…] or :deprecated[…] inside an entry (its cells, detail or body) sets fields and values for since / deprecated when the entry does not state them; see Inline Roles.

Diagnostics of reference tables have stable codes (listed in Reference Tables); entry-unmatched and entry-attribute-typo are info, which never fail a strict check.

PayloadMarkdownConfig

1type PayloadMarkdownConfig = {2  code?: MarkdownCodeConfig3  collections?: Partial<Record<CollectionSlug, PayloadMarkdownCollectionConfig | true>>4  config?: ConfigOptions5  enabled?: boolean6  icons?: PayloadMarkdownIconsConfig7  themes?: MarkdownDirectiveThemes8}

enabled defaults to enabled behavior. Set enabled: false only when you want the plugin to return the incoming Payload config unchanged.

PayloadMarkdownIconsConfig

1type PayloadMarkdownIconPack = {2  alias: string3  path: string4}5 6type PayloadMarkdownIconsConfig = {7  baseDir: string8  packs: PayloadMarkdownIconPack[]9}

Icon refs in Markdown use @pack/name, such as @fa-duotone/home. The plugin validates pack aliases, pack paths, icon refs, traversal attempts, unknown packs, and missing SVG files.

PayloadMarkdownCollectionConfig

1type PayloadMarkdownCollectionConfig = {2  code?: MarkdownCodeConfig3  config?: ConfigOptions4  field?: Omit<MarkdownFieldOptions, 'name'>5  fieldName?: string6  installField?: boolean7  installIntoBlocks?: boolean8  themes?: MarkdownDirectiveThemes9}

MarkdownCodeConfig

1type MarkdownCodeConfig = {2  enhanced?: boolean3  fullBleed?: boolean4  langs?: string[]5  lineNumbers?: boolean6  shikiTheme?: string7}

Defaults:

  • enhanced: true
  • lineNumbers: true when enhanced rendering is enabled
  • shikiTheme: github-dark
  • fullBleed: false

MarkdownConfig

1type MarkdownConfig = {2  className?: string3  enableGutter?: boolean4  lead?: ReactNode5  mutedHeadings?: boolean6  size?: 'lg' | 'md' | 'sm'7  variant?: 'blog' | 'compact' | 'docs' | 'unstyled'8  wrapperClassName?: string9 10  // Deprecated aliases11  columnClassName?: string12  fullBleedCode?: boolean13  options?: RenderMarkdownOptions14  sectionClassName?: string15}

MarkdownRenderConfig

1type MarkdownRenderConfig = {2  code?: MarkdownCodeConfig3  directives?: { presets?: Record<string, MarkdownDirectivePreset> }4  docs?: MarkdownDocsConfig5  icons?: PayloadMarkdownIconsConfig6  resolve?: MarkdownResolveConfig // host lookups, server only (below)7  themes?: MarkdownDirectiveThemes8} & MarkdownConfig9 10// Host lookups for what the page cannot answer itself. Each may be async and11// returns undefined or null when the host does not know the target.12type MarkdownResolveConfig = {13  page?: (href: string) => MarkdownResolvedPage | null | undefined | Promise<MarkdownResolvedPage | null | undefined>14  ref?: (target: string) => MarkdownResolvedRef | null | undefined | Promise<MarkdownResolvedRef | null | undefined>15}16 17type MarkdownResolvedRef = { href: string; title?: string }18type MarkdownResolvedPage = { description?: string; title?: string }19 20// A short directive name: `:::flags` reads as `:::docs-table{kind="options"}`.21type MarkdownDirectivePreset = { attributes?: Record<string, boolean | string>; use: string }22 23// Reference-table kinds to add, or to change field by field.24type MarkdownDocsConfig = { kinds?: Record<string, MarkdownDocsKind> }25 26type MarkdownDocsKind = {27  columns?: string[] // default columns of an entries-only table28  description?: string29  empty?: string[] // values that mean "no value" for fact checks30  entry?: string // row kind (data-kind)31  entryKinds?: Array<{ kind: string; prefix: string }> // row kinds chosen by name prefix32  extends?: string // default 'generic'33  fields?: Record<string, MarkdownDocsKindField>34  layout?: 'list' | 'table' | 'tree'35  tree?: string // default tree separator36}37 38type MarkdownDocsKindField = {39  aliases?: string[] // header texts that map to the field, case-insensitive40  inline?: boolean // shown after the name when not a column41  label?: string42  prose?: boolean // never compared by pmdocs facts check43  render?: 'badge' | 'boolean' | 'code' | 'markdown' | 'type'44}

docs and directives layer like themes: plugin, collection, then render config.

resolve

1type MarkdownResolveConfig = {2  page?: (href: string) => MarkdownResolvedPage | null | undefined | Promise<MarkdownResolvedPage | null | undefined>3  ref?: (target: string) => MarkdownResolvedRef | null | undefined | Promise<MarkdownResolvedRef | null | undefined>4}5 6type MarkdownResolvedPage = { description?: string; title?: string }7type MarkdownResolvedRef = { href: string; title?: string }

resolve holds lookups the renderer cannot answer from the page itself; every function is optional, may be async, and returns null or undefined when the host does not know the target. page is called by :::related with a card's URL as authored (the same value as in links), once per URL and render, only for cards that need it: its title replaces a link text that is empty or the URL itself, and its description is shown when the item has none. Without page, or when it returns nothing, a card shows what was authored. A lookup that throws is reported as related-resolve-failed (a warning) and leaves the card as authored.

Pass resolve to renderMarkdown() or as a MarkdownRenderer prop. The functions stay on the server: MarkdownRenderer is a server component and hands its client component only an element id, so do not pass resolve from a client component. Plugin options do not take resolve; each layer of render config that sets a function replaces that function only.

resolve.ref(target) is asked for a :ref that names no entry or heading on the page (target is the reference as plain text, --mode or remote add); return { href, title } to link it, for example to another page of the docs set. Results are used only when href is a relative URL or uses an allowed protocol; within one render each target is asked once. Without a result the reference is unresolved-ref and renders as text; a resolver that throws or rejects is ref-resolve-failed (warning) and the render continues. resolve holds functions, so pass it to renderMarkdown or MarkdownRenderer on the server; it is never sent to a client component. In the editor linter, lintMarkdownDirectives(markdown, { externalRefs: true }) leaves such references unreported.

ConfigOptions

config can be shared or split by field and block scope:

1type ConfigOptions =2  | MarkdownConfig3  | {4      blocks?: MarkdownConfig5      field?: MarkdownConfig6    }

Renderer Props

1type MarkdownRendererProps = {2  as?: keyof JSX.IntrinsicElements3  collectionSlug?: string4  emptyFallback?: ReactNode5  errorFallback?: ReactNode6  markdown?: null | string7  scope?: 'blocks' | 'field'8  settings?: PayloadMarkdownSettingsSource | false | null9} & MarkdownRenderConfig

Markdown Field Options

1type MarkdownFieldOptions = {2  admin?: Partial<TextField['admin']>3  defaultValue?: string4  label?: string5  localized?: boolean6  name?: string7  required?: boolean8}

Directive Names

Layout directives:

  • section
  • 2col
  • 3col
  • cell

Static directives:

  • badge
  • badges
  • button
  • buttons
  • callout
  • details
  • toc
  • steps
  • cards
  • card
  • tabs
  • tab
  • related

Reference directives:

  • docs-table (also ::docs-table directly above a pipe table)
  • entry
  • index
  • usage (::usage[synopsis], also a ```usage fence)
  • exchange

Inline roles (:name[label]{attributes}, see Inline Roles):

  • kbd
  • since
  • deprecated
  • ref (to)
  • fact (id, field)

Close markers:

  • :::
  • :::end
  • :::endcol
  • :::endsection

Directive Theme Groups

1type MarkdownDirectiveThemes = {2  callout?: MarkdownDirectiveThemeGroup3  card?: MarkdownDirectiveThemeGroup4  cards?: MarkdownDirectiveThemeGroup5  cell?: MarkdownDirectiveThemeGroup6  columns?: MarkdownDirectiveThemeGroup7  details?: MarkdownDirectiveThemeGroup8  docsTable?: MarkdownDirectiveThemeGroup9  entry?: MarkdownDirectiveThemeGroup10  exchange?: MarkdownDirectiveThemeGroup11  index?: MarkdownDirectiveThemeGroup12  related?: MarkdownDirectiveThemeGroup13  section?: MarkdownDirectiveThemeGroup14  steps?: MarkdownDirectiveThemeGroup15  tab?: MarkdownDirectiveThemeGroup16  tabs?: MarkdownDirectiveThemeGroup17  toc?: MarkdownDirectiveThemeGroup18}

Theme items use classes:

1type MarkdownDirectiveTheme = {2  classes: string3  label?: string4  name: string5}

Default Theme Names

Callout:

  • soft
  • solid
  • glass

Card:

  • default
  • muted
  • glass
  • cyan
  • violet
  • emerald
  • amber
  • danger

Cards:

  • default
  • compact
  • spacious
  • feature-grid

Steps:

  • default
  • muted
  • glass
  • cyan

Tabs:

  • default
  • muted
  • glass
  • underline
  • pills

Tab:

  • default
  • muted
  • glass

Details:

  • default
  • muted
  • glass

Docs table:

  • default
  • panel
  • muted
  • glass
  • plain

Entry:

  • default
  • muted
  • glass
  • plain

Related:

  • default
  • muted
  • plain

Index:

  • default
  • panel
  • muted

TOC:

  • default
  • compact
  • sidebar

Section:

  • default
  • muted
  • panel

Columns:

  • default
  • panel

Cell:

  • default
  • panel