# @m2d/table

> Plugin to convert Markdown tables (MDAST) to DOCX with support for rich formatting and seamless integration into mdast2docx.

Latest version **0.1.3** (published 2026-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @m2d/table
pnpm add @m2d/table
yarn add @m2d/table
bun add @m2d/table
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2026-10-21 |
| First published | 2025-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mayank Kumar Chaudhari <https://mayankchaudhari.com> |
| Maintainers | mayank1513 |
| Keywords | table-plugin, tables, mdast-tables, markdown-tables, docx-tables, markdown-to-docx, mdast-to-docx, mdast, markdown, plugin, converter, docx, ms-word, export, document-generator, document-generation, text-processing, remark, unified, typescript, open-source, customizable, seamless-integration, modern, web-development, automation, google-sheets, rich-text, compatibility, progressive, cutting-edge, frontend, generative-ai, md2docx, mdast2docx, m2d, mayank1513 |

## Links

- npm: https://www.npmjs.com/package/@m2d/table
- Repository: https://github.com/md2docx/md2docx
- Homepage: https://github.com/md2docx/md2docx/blob/main/packages/table/README.md
- Issues: https://github.com/md2docx/md2docx/issues
- Funding: https://github.com/sponsors/md2docx
- npm.io page: https://npm.io/package/@m2d/table

## Dependencies (1)

- [@m2d/core](https://npm.io/package/@m2d/core.md) 1.8.1

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2026-10-21
- 0.1.2 — 2026-10-20
- 0.1.1 — 2025-09-22
- 0.1.0 — 2025-09-14
- 0.0.7 — 2025-06-24
- 0.0.6 — 2025-05-29
- 0.0.5 — 2025-05-20
- 0.0.4 — 2025-04-08
- 0.0.3 — 2025-03-26
- 0.0.2 — 2025-03-24
- 0.0.1 — 2025-03-24
- 0.0.0 — 2025-03-23

## README

# @m2d/table <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>

<p className="flex gap-2">
  <a href="https://github.com/md2docx/md2docx/actions/workflows/ci.yml" rel="noopener noreferrer">
    <img alt="CI" src="https://github.com/md2docx/md2docx/actions/workflows/ci.yml/badge.svg" />
  </a>
  <a href="https://codecov.io/gh/md2docx/md2docx/tree/main/packages/@m2d/table" rel="noopener noreferrer">
    <img alt="codecov" src="https://codecov.io/gh/md2docx/md2docx/graph/badge.svg?flag=@m2d/table" />
  </a> 
  <a href="https://npmjs.com/package/@m2d/table" rel="noopener noreferrer">
    <img alt="npm version" src="https://img.shields.io/npm/v/@m2d/table" />
  </a>
  <a href="https://npmjs.com/package/@m2d/table" rel="noopener noreferrer">
    <img alt="npm downloads" src="https://img.shields.io/npm/d18m/@m2d/table" />
  </a>
  <a href="https://npmjs.com/package/@m2d/table" rel="noopener noreferrer">
    <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@m2d/table" />
  </a>
  <img alt="license" src="https://img.shields.io/npm/l/@m2d/table" />
</p>

> @m2d/table: Markdown Table formatting plugin for `@m2d/core`. Renders rich, customizable Word tables with column alignment, borders, cell shading, and repeating headers.

---

## ✨ Features

- 📊 **Native Word Tables**: Converts Markdown GFM tables into clean `docx.Table` elements with authentic Word OpenXML borders and paddings.
- 🎯 **Automatic Column Alignment**: Honors Markdown column alignments (`left`, `center`, `right`) with fallback defaults.
- 🎨 **Rich Cell Styling**: Style headers and data cells with background fills (`shading`), custom typography (fonts, sizes, colors), and paragraph spacing via the `data` option.
- 📄 **Multi-Page Header Repetition**: Automatically repeats header rows across page breaks (`tableHeader: true`).
- 🧱 **Block Content in Cells**: Seamlessly accommodates nested paragraphs, lists, code snippets, and blockquotes inside table cells (ideal when paired with `@m2d/html`).

---

## 📦 Installation

```bash
$ pnpm add @m2d/table @m2d/core docx
```

**_or_**

```bash
$ npm install @m2d/table @m2d/core docx
```

**_or_**

```bash
$ yarn add @m2d/table @m2d/core docx
```

---

## 🚀 Quick Start

```typescript
import { toDocx } from "@m2d/core";
import { tablePlugin } from "@m2d/table";
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
import { unified } from "unified";

const markdown = `
# Quarterly Summary

| Quarter | Revenue | Growth | Status |
| :------ | :-----: | -----: | :----: |
| Q1      | $1.2M   | +12%   | Active |
| Q2      | $1.5M   | +25%   | Active |
| Q3      | $1.8M   | +20%   | Active |
`;

const mdast = unified().use(remarkParse).use(remarkGfm).parse(markdown);

const docxBlob = await toDocx(mdast, {}, {
  plugins: [tablePlugin()],
});
```

---

## ⚙️ Plugin Options

```typescript
import { AlignmentType, ShadingType, VerticalAlignTable } from "docx";

tablePlugin({
  // Table level properties (width, margins, borders)
  tableProps: { ... },

  // General row properties
  rowProps: { cantSplit: true },

  // First row (header) properties
  firstRowProps: { tableHeader: true },

  // Header cell styling
  firstRowCellProps: {
    shading: { type: ShadingType.SOLID, fill: "1E293B" },
    data: { bold: true, color: "FFFFFF", alignment: AlignmentType.CENTER },
  },

  // Body cell styling
  cellProps: {
    data: { size: 20, font: "Segoe UI" },
  },

  // Alignment configuration
  alignments: {
    preferMdData: true,
    defaultHorizontalAlign: AlignmentType.LEFT,
    defaultVerticalAlign: VerticalAlignTable.CENTER,
  },
});
```

---

## 📚 Deep Dive Guides

- 🎨 **[Table Styling & Layout Guide](./docs/table-styling-and-layout.mdx)**: Margins, border styles, widths, and repeating multi-page headers.
- 🔠 **[Cell Formatting & Alignment Guide](./docs/cell-formatting-and-alignment.mdx)**: Markdown alignment hierarchy, typography, cell shading, and block content in cells.

---

## License

This library is licensed under the MIT open-source license.

<hr />

<p align="center">with 💖 by <a href="https://mayankchaudhari.com" target="_blank">Mayank Kumar Chaudhari</a></p>

---
_Source: https://npm.io/package/@m2d/table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
