🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@m2d/table

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@m2d/table

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

0.0.4
latest
Source
npm
Version published
Weekly downloads
848
2.54%
Maintainers
1
Weekly downloads
 
Created
Source

@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: { ... },
  firstRowProps: { ... },
  firstRowCellProps: { ... },
  alignments: {
    defaultHorizontalAlign: AlignmentType.CENTER,
    defaultVerticalAlign: VerticalAlign.CENTER,
    preferMdData: true,
  },
});

All options override the following sensible defaults:

Default Table Style

PropertyDefault Value
Table Width100% (percentage)
Border StyleSINGLE, size 1
Cell Padding2–4mm margins (top/bottom/left/right)
Header RowBold with shaded background #b79c2f
Vertical AlignmentCENTER
Horizontal AlignmentBased on Markdown or CENTER fallback

🧪 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

Made with 💖 by Mayank Kumar Chaudhari

Keywords

table-plugin

FAQs

Package last updated on 08 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts