← Changelog

remark-citations plugin — hex-code footnote renumbering and structured definition parsing

New Plugin: remark-citations

Added remark-citations to the LFM pipeline. Transforms footnote identifiers (hex codes, numeric, or mixed) into sequentially-numbered citations with structured metadata parsing.

What It Does

  • Walks the MDAST depth-first, collecting footnoteReference nodes in document order
  • Assigns sequential indices (1, 2, 3…) by order of first appearance — not by identifier value
  • Parses structured definitions: [Title](URL), source domain, Published: / Updated: dates, year prefixes
  • Enriches footnoteReference nodes with data.citationIndex and data.citationHex
  • Removes footnoteDefinition nodes from the tree (consumers render via tree.data.citations)
  • Attaches tree.data.citations with map, ordered array, and warnings
  • Validates orphan references and unused definitions at build time
  • Supports source-ref attributes on directive nodes for image source attribution

Identifier Modes

  • hex — Authors use hex codes ([^a1b2c3]), plugin renumbers to [1], [2], etc.
  • numeric — Authors use numbers ([^1]), plugin auto-assigns hex codes for stability
  • mixed (default) — Both styles accepted without warnings

Pipeline Position

Runs after remark-gfm (which creates footnote nodes) and after remark-callouts. Enabled by default via remarkLfm({ citations: true }).

Exports

  • remarkCitations — the plugin function
  • Citation, CitationsData, CitationWarning, RemarkCitationsOptions — TypeScript types

Files

New

  • src/plugins/remark-citations.ts — Plugin implementation

Modified

  • src/index.ts — Added citations exports
  • src/preset.ts — Wired citations into remarkLfm pipeline
  • src/types/index.ts — Added citations option to RemarkLfmOptions
  • tsup.config.ts — Added plugins/remark-citations build entry