@adobe/micromark-extension-gridtables

中文文档
2.0.5发布于 2026/10/12Apache-2.0ES Module构建来源已验证近 30 天下载 8.4万

Micromark Extension Gridtables

原始使用文档
文档目录14 节
  1. Status
  2. What is this?
  3. When to use this
  4. Overview
  5. Syntax
  6. Usage
  7. Parsing with unified
  8. Generating HAST
  9. Generating HTML
  10. Installation
  11. Development
  12. Build
  13. Test
  14. Lint

Micromark Extension Gridtables

Micormark extension to parse markdown gridtables.

Status

codecov GitHub Actions Workflow Status GitHub license GitHub issues semantic-release

Grid Tables

What is this?

This package contains extensions that add support for gridtables to micromark.

When to use this

These tools are all low-level. In many cases, you want to use @adobe/remark-gridtables with remark instead.

When working with mdast-util-from-markdown, you must combine this package with @adobe/mdast-util-gridtables.

Overview

GridTables look like this:

+-------------------+------+
| Table Headings    | Here |
+--------+----------+------+
| Sub    | Headings | Too  |
+========+=================+
| cell   | column spanning |
| spans  +---------:+------+
| rows   |   normal | cell |
+---v----+:---------------:+
|        | cells can be    |
|        | *formatted*     |
|        | **paragraphs**  |
|        | ```             |
| multi  | and contain     |
| line   | blocks          |
| cells  | ```             |
+========+=========<+======+
| footer |    cells |      |
+--------+----------+------+
  • the top of a cell must be indicated by +- followed by some - or + and finished by -+.
  • if the table contains a footer but no header, the top row should use = as grid line.
  • col spans are indicated by missing column (|) delimiters
  • row spans are indicated by missing row (-) delimiters
  • cells can be left, center, right, or justify aligned; indicated by the placement of : or ><
  • cells can be top, middle, or bottom v-aligned; indicated by the placement of arrows (v ^ x)
  • the header and footer sections are delimited by section delimiters (=).
  • if no section delimiters are present, all cells are placed in the table body.
  • if only 1 section delimiter is present, it delimits header from body.
  • the content in cells can be a full Markdown document again. note, that the cell boundaries (|) need to exactly match with the column markers (+) in the row delimiters, if the cell content contains |, otherwise the correct layout of the table can't be guaranteed.

Layout

The table layout tries to keep the table within a certain width (default 120). For example, if the table has 3 columns, each column will be max 40 characters wide. If all text in a column is smaller, it will shrink the columns. However, cells have a minimum width (default 10) when text needs to be broken. If the cell contents need more space, e.g. with a nested table or code block, it will grow accordingly.

Align

Horizontal align is indicated by placing markers at the grid line above the cell:

Justify     Center     Left       Right
+>-----<+  +:-----:+  +:------+  +------:+
| A b C |  |  ABC  |  | ABC   |  |   ABC |
+-------+  +-------+  +-------+  +-------+

Vertical align is indicated by placing markers at the center of the grid line above the cell:

Top        Middle     Bottom
+---^---+  +---x---+  +---v---+
| Larum |  |       |  |       |
| Ipsum |  | Larum |  |       |
|       |  | Ipsum |  | Larum |
|       |  |       |  | Ipsum |
+-------+  +-------+  +-------+

Syntax


gridTable := gridLine cellLine+ gridLine;
gridLine := gridCell+ "+";
cellLine := ( gridCell | cellContent )+ ( "+" | "|" );   
gridCell := "+" alignMarkerStart? ("-" | "=")+ vAlignMarker? ("-" | "=")* alignMarkerEnd?;
cellContent := ( "+" | "|" ) " " content " " ;
alignMarkerStart := ":" | ">";
alignMarkerEnd   := ":" | "<";
vAlignMarker     := "^" | "v" | "x"

Usage

Parsing with unified

import { unified } from 'unified';
import remarkParse from 'remark-parse';
import { remarkGridTable } from '@adobe/remark-gridtables';

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

Generating HAST

import { toHast, defaultHandlers } from 'mdast-util-to-hast';
import { mdast2hastGridTableHandler, TYPE_TABLE } from '@adobe/helix-markdown-support/gridtable';

const hast = toHast(mdast, {
  handlers: {
    ...defaultHandlers,
    [TYPE_TABLE]: mdast2hastGridTableHandler(),
  },
  allowDangerousHtml: true,
});

Generating HTML

import {micromark} from 'micromark'
import {gridTables, gridTablesHtml} from '@adobe/micromark-extension-gridtables'

const html = micromark(markdown, {
  extensions: [gfmTable],
  htmlExtensions: [gfmTableHtml]
})

console.log(html)

Installation

$ npm install @adobe/micromark-extension-gridtables

Development

Build

$ npm install

Test

$ npm test

Lint

$ npm run lint

版本与发布记录

@adobe/micromark-extension-gridtables 共发布 11 个版本,首次发布于 2022/10/07;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.5latest2026/10/1224 天前
2.0.42025/06/171.4 年前
2.0.32025/03/021.7 年前
2.0.22024/04/022 年前
2.0.12024/04/022 年前
2.0.02023/07/103 年前

关于 @adobe/micromark-extension-gridtables 的常见问题

@adobe/micromark-extension-gridtables 是什么?

Micromark Extension Gridtables

如何安装 @adobe/micromark-extension-gridtables?

在项目目录运行 npm install @adobe/micromark-extension-gridtables,或使用 pnpm add / yarn add / bun add。

@adobe/micromark-extension-gridtables 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__micromark-extension-gridtables 是否存在。

@adobe/micromark-extension-gridtables 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adobe/micromark-extension-gridtables 可以商用吗?

@adobe/micromark-extension-gridtables 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/micromark-extension-gridtables 的下载量有多少?

根据 npm 官方下载统计,@adobe/micromark-extension-gridtables 在 2026/10/05 – 2026/11/03 这 30 天内被下载 83,964 次,日均约 2,799 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/micromark-extension-gridtables 还在维护吗?

最新版本 2.0.5 发布于 2026/10/12(24 天前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2022/10/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。