npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@m2d/table

v0.1.1

Published

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

Downloads

28,789

Readme

@m2d/table

test codecov Version Downloads Bundle Size

A plugin that converts Markdown tables into rich, styled Word tables with full alignment, border, and header support.


📦 Installation

npm install @m2d/table
pnpm add @m2d/table
yarn add @m2d/table

🚀 Overview

The @m2d/table plugin for mdast2docx renders Markdown tables into Word-compatible tables with customizable layout, alignment, and cell styling using the docx library.

Automatically handles header rows, borders, shading, cell alignments, and padding — all configurable.


✨ Features

  • Transforms Markdown tables into docx.Table elements
  • Auto-detects column alignment from MDAST (left, center, right)
  • Customizable:
    • Table width and border styles
    • Cell padding and shading
    • Header row formatting
    • Horizontal and vertical alignment
  • Graceful fallback to defaults if MDAST alignment is missing

🛠️ Usage

import { toDocx } from "@m2d/core";
import { tablePlugin } from "@m2d/table";

const plugins = [tablePlugin()];

const buffer = await toDocx(mdastTree, {
  plugins,
});

⚙️ Options

The tablePlugin accepts an optional configuration object:

tablePlugin({
  tableProps: { ... },
  rowProps: { ... },
  cellProps: {
    ... // CellProps
    data: { bold: true, color: "#000000" } // Paragraph and Run styling options
  },
  firstRowProps: { ... },
  firstRowCellProps: {
    data: { bold: true, alignment: AlignmentType.CENTER } // Header cell styling
  },
  alignments: {
    defaultHorizontalAlign: AlignmentType.CENTER,
    defaultVerticalAlign: VerticalAlign.CENTER,
    preferMdData: true,
  },
});

All options override the following sensible defaults:

Default Table Style

| Property | Default Value | | -------------------- | -------------------------------------- | | Table Width | 100% (percentage) | | Border Style | SINGLE, size 1 | | Cell Padding | 2–4mm margins (top/bottom/left/right) | | Header Row | Bold with shaded background #b79c2f | | Cell Styling | Full docx.js paragraph & run options | | Vertical Alignment | CENTER | | Horizontal Alignment | Based on Markdown or CENTER fallback |

Advanced Cell Styling with data Property

The data property provides comprehensive styling control using docx.js paragraph and text run options:

Text Run Styling (IRunOptions)

  • bold, italics, underline, strike, doubleStrike
  • color, size (font size in half-points)
  • font (font family), highlight, shading
  • superScript, subScript, smallCaps, allCaps

Paragraph Styling (IParagraphOptions)

  • alignment - text alignment (LEFT, CENTER, RIGHT, JUSTIFIED)
  • spacing - line spacing and paragraph spacing
  • indent - left, right, first line, hanging indents
  • numbering, bullet, style

Code Block Support

  • pre: true - preserves spaces, newline for code blocks
tablePlugin({
  cellProps: {
    data: {
      font: "Arial",
      size: 20, // 10pt font
      color: "#333333",
      spacing: { after: 120 }, // 6pt spacing after
    },
  },
  firstRowCellProps: {
    data: {
      bold: true,
      alignment: AlignmentType.CENTER,
      color: "#ffffff",
      size: 24, // 12pt font
      font: "Calibri",
    },
  },
});

🧪 Example

Markdown Input

| Name  | Age |      City |
| :---: | :-: | --------: |
| Alice | 24  |  New York |
|  Bob  | 30  | San Diego |

Output DOCX

  • The first row is treated as a header, with custom shading.
  • Column alignment is preserved: center, center, right.

🔍 Internals

  • Leverages docx.Table, docx.TableRow, docx.TableCell, and docx.Paragraph
  • Dynamically maps Markdown alignment via MDAST.align[]
  • Uses @m2d/core’s block plugin API
  • Prevents re-processing of transformed nodes by setting node.type = ""

⚠️ Limitations

  • Does not support row/column spans
  • MDAST source must conform to GFM tables
  • Table styling is fixed to plugin options; no per-cell customization via Markdown yet

⭐ Support Us

If you find this useful:


🧾 License

MIT © Mayank Chaudhari