mdast-util-gfm-table
mdast extensions to parse and serialize GitHub Flavored Markdown tables.
Repository Health
Technical Analysis
mdast-util-gfm-table is part of the unified/syntax-tree ecosystem and provides two extensions that add GitHub Flavored Markdown table support to mdast, the markdown abstract syntax tree. One extension plugs into mdast-util-from-markdown to parse pipe tables into structured table, tableRow, and tableCell nodes, and the other plugs into mdast-util-to-markdown to serialize those nodes back to markdown.
It preserves per-column alignment and handles the alignment of cell content when stringifying, producing neatly padded tables. It is typically combined with micromark-extension-gfm-table for tokenization, and is one of the building blocks used by mdast-util-gfm and remark-gfm.
What You Get
- A from-markdown extension that parses pipe tables into table, tableRow, and tableCell nodes
- A to-markdown extension that serializes table nodes back to aligned GFM markdown
- Preservation of per-column alignment (left, right, center, none)
- Options to control cell padding and alignment delimiters when serializing
- TypeScript type definitions and lossless round-tripping of table syntax
Common Use Cases
- Adding table support to a remark or unified markdown pipeline
- Parsing GFM tables into an mdast tree for programmatic transformation
- Serializing generated table nodes back into markdown documents
- Building custom GFM tooling alongside micromark-extension-gfm-table
Under The Hood
Architecture - The package is implemented in a single lib/index.js (~303 lines) exporting two objects. The from-markdown extension registers enter/exit handlers for micromark table token events, building table/tableRow/tableCell nodes and recording an align array on the table node. The to-markdown extension measures cell widths and renders aligned, padded rows, honoring the recorded alignment and configurable padding options.
Tech Stack - Pure ESM JavaScript typed via JSDoc with generated index.d.ts declarations. It depends on sibling unist/mdast utilities and markdown-table for width-aware rendering, targeting modern Node.js and browsers.
Code Quality - The code follows the strict, uniform conventions of the syntax-tree project, with a dedicated test.js suite and full type coverage. Alignment and padding logic is isolated and well tested.
API Design - The two-function, from/to naming mirrors every other mdast-util extension, so it drops into existing pipelines with no new concepts. It composes by being passed into from-markdown/to-markdown option arrays alongside its micromark counterpart.