mdast-util-gfm-table
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -21,2 +21,3 @@ /** | ||
export type ToMarkdownContext = import('mdast-util-to-markdown').Context | ||
export type SafeOptions = import('mdast-util-to-markdown').SafeOptions | ||
export type Options = { | ||
@@ -23,0 +24,0 @@ tableCellPadding?: boolean | undefined |
47
index.js
@@ -13,2 +13,3 @@ /** | ||
* @typedef {import('mdast-util-to-markdown').Context} ToMarkdownContext | ||
* @typedef {import('mdast-util-to-markdown').SafeOptions} SafeOptions | ||
* | ||
@@ -146,5 +147,8 @@ * @typedef Options | ||
*/ | ||
function handleTable(node, _, context) { | ||
// @ts-expect-error: fixed in `markdown-table@3.0.1`. | ||
return serializeData(handleTableAsData(node, context), node.align) | ||
function handleTable(node, _, context, safeOptions) { | ||
return serializeData( | ||
handleTableAsData(node, context, safeOptions), | ||
// @ts-expect-error: fixed in `markdown-table@3.0.1`. | ||
node.align | ||
) | ||
} | ||
@@ -160,4 +164,4 @@ | ||
*/ | ||
function handleTableRow(node, _, context) { | ||
const row = handleTableRowAsData(node, context) | ||
function handleTableRow(node, _, context, safeOptions) { | ||
const row = handleTableRowAsData(node, context, safeOptions) | ||
// `markdown-table` will always add an align row | ||
@@ -172,6 +176,7 @@ const value = serializeData([row]) | ||
*/ | ||
function handleTableCell(node, _, context) { | ||
function handleTableCell(node, _, context, safeOptions) { | ||
const exit = context.enter('tableCell') | ||
const subexit = context.enter('phrasing') | ||
const value = containerPhrasing(node, context, { | ||
...safeOptions, | ||
before: around, | ||
@@ -186,4 +191,4 @@ after: around | ||
/** | ||
* @param {Array.<Array.<string>>} matrix | ||
* @param {Array.<string>} [align] | ||
* @param {Array<Array<string>>} matrix | ||
* @param {Array<string>} [align] | ||
*/ | ||
@@ -202,7 +207,8 @@ function serializeData(matrix, align) { | ||
* @param {ToMarkdownContext} context | ||
* @param {SafeOptions} safeOptions | ||
*/ | ||
function handleTableAsData(node, context) { | ||
function handleTableAsData(node, context, safeOptions) { | ||
const children = node.children | ||
let index = -1 | ||
/** @type {Array.<Array.<string>>} */ | ||
/** @type {Array<Array<string>>} */ | ||
const result = [] | ||
@@ -212,3 +218,7 @@ const subexit = context.enter('table') | ||
while (++index < children.length) { | ||
result[index] = handleTableRowAsData(children[index], context) | ||
result[index] = handleTableRowAsData( | ||
children[index], | ||
context, | ||
safeOptions | ||
) | ||
} | ||
@@ -224,7 +234,8 @@ | ||
* @param {ToMarkdownContext} context | ||
* @param {SafeOptions} safeOptions | ||
*/ | ||
function handleTableRowAsData(node, context) { | ||
function handleTableRowAsData(node, context, safeOptions) { | ||
const children = node.children | ||
let index = -1 | ||
/** @type {Array.<string>} */ | ||
/** @type {Array<string>} */ | ||
const result = [] | ||
@@ -234,3 +245,11 @@ const subexit = context.enter('tableRow') | ||
while (++index < children.length) { | ||
result[index] = handleTableCell(children[index], node, context) | ||
// Note: the positional info as used here is incorrect. | ||
// Making it correct would be impossible due to aligning cells? | ||
// And it would need copy/pasting `markdown-table` into this project. | ||
result[index] = handleTableCell( | ||
children[index], | ||
node, | ||
context, | ||
safeOptions | ||
) | ||
} | ||
@@ -237,0 +256,0 @@ |
{ | ||
"name": "mdast-util-gfm-table", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "mdast extension to parse and serialize GFM tables", | ||
@@ -41,3 +41,3 @@ "license": "MIT", | ||
"markdown-table": "^3.0.0", | ||
"mdast-util-to-markdown": "^1.0.0" | ||
"mdast-util-to-markdown": "^1.3.0" | ||
}, | ||
@@ -44,0 +44,0 @@ "devDependencies": { |
18769
264