标记网格表
添加插件, 以解析并序列化缩放网格表 .
状态
这是什么?
这个软件包是 统一 (单位:千美元)评论) 启用网格表扩展的插件.
统一 用抽象语法树转换内容的工程 (ASTs) (英语). 评论 添加对减值的支持以统一. 目标数 是减价的AST 用来表示. 这是一个改变 mdast 的评论插件 .
我什么时候用这个?
此工程在您想要支持解析和序列化网格表时有用 .
此插件不处理如何将标记降为 HTML .
这是由 [remark-rehype[注-回].
安装
这个软件包是 仅限无害环境管理。 。 。 . 在Node.js(12.20+,14.14+,或16.0+)中,安装与 无数字 :
$ npm install @adobe/remark-gridtables
使用量
import { unified } from 'unified';
import stringify from 'remark-stringify';
import remark from 'remark-parse';
import remarkGridTable from '@adobe/remark-gridtables';
// markdown -> mdast
const mdast = unified()
.use(remark)
.use(remarkGridTable)
.parse(sourceMarkdown);
// mdast -> markdown
const outputMarkdown = unified()
.use(stringify)
.use(remarkGridTable)
.stringify(mdast);
另见 试验/实例.js 关于如何生成 HTML 表格.
概览
网格表是这样的:
+-------------------+------+
| 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 | |
+--------+----------+------+
- 单元格顶部必须用
+-接着是一些-或者说+完成于-+。 。 。 . - 如果表格包含页脚但没有页眉,则上行应当使用
=作为网格线. - col 跨度用缺一栏表示(
|(a) 划界人 - 缺行表示行长(
-(a) 划界人 - 单元格可以是左、中、右或对齐的理由;通过放置
:或者说>< - 单元格可以是上,中,或下相v;用箭头的放入表示(
v^x(中文(简体) ) - 标题和页脚段由区划符划定(
=) (中文(简体) ). - 如果没有分区分隔符,所有单元格都放在表格正文中.
- 如果只有1个区划符,则它从正文中划分标题.
- 单元格中的内容可以再次成为完整的Markdown文档。 注,单元格边界(
|(中文(简体) ) 需要与列标记完全匹配(+在行分隔符中,如果单元格内容 包含|,否则无法保证表格的正确布局.
版式
表格布局试图使表格保持一定的宽度(默认为120). 譬如说, 如果表格有3个栏,则每个栏将最大宽40个字符。 如果列中的所有文字 较小, 它会缩小柱子。 然而,当 文本需要被打破。 如果单元格内容需要更多的空格,例如有嵌入式表或 代码块,它会相应增长.
对齐
水平对齐通过在单元格上方的网格线上放置标记来表示:
Justify Center Left Right
+>-----<+ +:-----:+ +:------+ +------:+
| A b C | | ABC | | ABC | | ABC |
+-------+ +-------+ +-------+ +-------+
垂直对齐通过在单元格上方的网格线中心放置标记来表示:
Top Middle Bottom
+---^---+ +---x---+ +---v---+
| Larum | | | | |
| Ipsum | | Larum | | |
| | | Ipsum | | Larum |
| | | | | Ipsum |
+-------+ +-------+ +-------+
语法
gridTable := gridLine cellLine+ gridLine;
gridLine := gridCell+ "+";
cellLine := ( gridCell | cellContent )+ ( "+" | "|" );
gridCell := "+" alignMarkerStart? ("-" | "=")+ vAlignMarker? ("-" | "=")* alignMarkerEnd?;
cellContent := ( "+" | "|" ) " " content " " ;
alignMarkerStart := ":" | ">";
alignMarkerEnd := ":" | "<";
vAlignMarker := "^" | "v" | "x"
MDAST 语法树
以下接口被添加到 [沉 [ 由这个工具.
节点
GridTable
interface GridTable <: Parent {
type: "gridTable"
children: [GridTableHeader|GridTableBody|GridTableFooter]
}
GridTableHeader
interface GridTableHeader <: Parent {
type: "gtHead"
children: [GridTableRow]
}
GridTableBody
interface GridTableBody <: Parent {
type: "gtBody"
children: [GridTableRow]
}
GridTableFoot
interface GridTableFooter <: Parent {
type: "gtFoot"
children: [GridTableRow]
}
GridTableRow
interface GridTableRow <: Parent {
type: "gtRow"
children: [GridTableCell]
}
GridTableCell
interface GridTableCell <: Parent {
type: "gtCell"
colSpan: number >= 1
rowSpan: number >= 1
align: alignType
valign: valignType
children: [MdastContent]
}
网格表环 ([家长[dfn-parent])代表一个标题单元格 [网格表[dfn-table],如果其父母是[网格表头[术语],或数据 否则,单元格.
网格表环 可用于[网格表单[dfn-row-content] 内容有望. 其内容模式是[目标数[dfn-phrasing-content]内容,允许完整的mdast文档.
编号
alignType
enum alignType {
"left" | "right" | "center" | "justify" | null
}
valignType
enum alignType {
"top" | "bottom" | "middle" | null
}