tsondb 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -52,9 +52,13 @@ export type ListItemNode = {
|
|
|
52
52
|
export type TableBlockNode = {
|
|
53
53
|
kind: "table";
|
|
54
54
|
caption?: InlineMarkdownNode[];
|
|
55
|
+
columns: TableColumnStyleBlockNode[];
|
|
55
56
|
header: TableCellBlockNode[];
|
|
56
57
|
rows: TableRowBlockNode[] | TableSectionBlockNode[];
|
|
57
58
|
};
|
|
59
|
+
export type TableColumnStyleBlockNode = {
|
|
60
|
+
alignment?: "left" | "center" | "right";
|
|
61
|
+
};
|
|
58
62
|
export type TableSectionBlockNode = {
|
|
59
63
|
kind: "tableSection";
|
|
60
64
|
header?: TableCellBlockNode[];
|
|
@@ -293,11 +293,32 @@ const parseContentRowForSyntaxHighlighting = (row) => row.split(/(\|+)/).reduce(
|
|
|
293
293
|
return [...acc, tableMarker(segment)];
|
|
294
294
|
}
|
|
295
295
|
}, []);
|
|
296
|
+
const trimPipes = (text) => text.replace(/^\|/, "").replace(/\|$/, "");
|
|
297
|
+
const parseTableAlignment = (text) => {
|
|
298
|
+
const trimmed = text.trim();
|
|
299
|
+
if (/^:-+:$/.test(trimmed)) {
|
|
300
|
+
return "center";
|
|
301
|
+
}
|
|
302
|
+
else if (/^:-+$/.test(trimmed)) {
|
|
303
|
+
return "left";
|
|
304
|
+
}
|
|
305
|
+
else if (/^-+:$/.test(trimmed)) {
|
|
306
|
+
return "right";
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
296
312
|
const tableRule = {
|
|
297
313
|
pattern: /^(?:(\|#)(.+?)(#\|)\n)?(\|)?(.+?(?:(?<!\\)\|.+?)+)((?<!\\)\|)?\n((?:\| *)?(?:-{3,}|:-{2,}|-{2,}:|:-+:)(?: *\| *(?:-{3,}|:-{2,}|-{2,}:|:-+:))*(?: *\|)?)((?:\n\|?.+?(?:(?<!\\)\|+.+?)*(?:(?<!\\)\|+)?)+)(\n{2,}|$)/,
|
|
298
|
-
map: ([_res, _captionMarkerStart, caption, _captionMarkerEnd, _headerMarkerStart, headers, _headerMarkerEnd,
|
|
314
|
+
map: ([_res, _captionMarkerStart, caption, _captionMarkerEnd, _headerMarkerStart, headers, _headerMarkerEnd, bodySeparators = "", body, _trailingWhitespace,]) => omitUndefinedKeys({
|
|
299
315
|
kind: "table",
|
|
300
316
|
caption: caption !== undefined ? parseInlineMarkdown(caption.trim(), false) : undefined,
|
|
317
|
+
columns: trimPipes(bodySeparators)
|
|
318
|
+
.split("|")
|
|
319
|
+
.map(col => omitUndefinedKeys({
|
|
320
|
+
alignment: parseTableAlignment(col),
|
|
321
|
+
})),
|
|
301
322
|
header: headers ? parseContentRow(headers) : [],
|
|
302
323
|
rows: body
|
|
303
324
|
?.split("\n")
|
|
@@ -17,7 +17,7 @@ export const BlockMarkdown = ({ node, outerHeadingLevel = 0, insertBefore, }) =>
|
|
|
17
17
|
return (_jsxs(_Fragment, { children: [insertBefore, _jsx("ul", { children: node.content.map((item, ii) => (_jsx("li", { children: item.content.map((inline, iii) => (_jsx(InlineMarkdown, { node: inline }, iii))) }, ii))) })] }));
|
|
18
18
|
}
|
|
19
19
|
case "table":
|
|
20
|
-
return (_jsxs(_Fragment, { children: [insertBefore, _jsxs("table", { children: [node.caption !== undefined && (_jsx("caption", { children: node.caption.map((inline, ci) => (_jsx(InlineMarkdown, { node: inline }, ci))) })), _jsx("thead", { children: _jsx(TableRow, { cells: node.header, cellType: "th" }) }), checkTableRowsAreSections(node.rows) ? (node.rows.map((section, si) => (_jsxs("tbody", { children: [section.header && _jsx(TableRow, { cells: section.header, cellType: "th" }), section.rows.map((row, ri) => (_jsx(TableRow, { cells: row.cells }, ri)))] }, si)))) : (_jsx("tbody", { children: node.rows.map((row, ri) => (_jsx(TableRow, { cells: row.cells }, ri))) }))] })] }));
|
|
20
|
+
return (_jsxs(_Fragment, { children: [insertBefore, _jsxs("table", { children: [node.caption !== undefined && (_jsx("caption", { children: node.caption.map((inline, ci) => (_jsx(InlineMarkdown, { node: inline }, ci))) })), _jsx("thead", { children: _jsx(TableRow, { columns: node.columns, cells: node.header, cellType: "th" }) }), checkTableRowsAreSections(node.rows) ? (node.rows.map((section, si) => (_jsxs("tbody", { children: [section.header && (_jsx(TableRow, { columns: node.columns, cells: section.header, cellType: "th" })), section.rows.map((row, ri) => (_jsx(TableRow, { columns: node.columns, cells: row.cells }, ri)))] }, si)))) : (_jsx("tbody", { children: node.rows.map((row, ri) => (_jsx(TableRow, { columns: node.columns, cells: row.cells }, ri))) }))] })] }));
|
|
21
21
|
case "container":
|
|
22
22
|
return (_jsxs("div", { class: node.name, children: [insertBefore, node.content.map((childNode, i) => (_jsx(BlockMarkdown, { node: childNode, outerHeadingLevel: outerHeadingLevel }, i)))] }));
|
|
23
23
|
case "footnote": {
|
|
@@ -30,7 +30,15 @@ export const BlockMarkdown = ({ node, outerHeadingLevel = 0, insertBefore, }) =>
|
|
|
30
30
|
return assertExhaustive(node);
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
const TableRow = ({ cells, cellType = "td", }) => {
|
|
33
|
+
const TableRow = ({ columns, cells, cellType = "td", }) => {
|
|
34
34
|
const CellTag = cellType;
|
|
35
|
-
return (_jsx("tr", { children: cells.
|
|
35
|
+
return (_jsx("tr", { children: cells.reduce(([elements, columnIndex], tc, ci) => [
|
|
36
|
+
[
|
|
37
|
+
...elements,
|
|
38
|
+
_jsx(CellTag, { scope: cellType === "th" && cells.length === 1 ? "colgroup" : undefined, colSpan: tc.colSpan, style: columns[columnIndex]?.alignment
|
|
39
|
+
? { textAlign: columns[columnIndex].alignment }
|
|
40
|
+
: undefined, children: tc.content.map((inline, cii) => (_jsx(InlineMarkdown, { node: inline }, cii))) }, ci),
|
|
41
|
+
],
|
|
42
|
+
columnIndex + (tc.colSpan ?? 1),
|
|
43
|
+
], [[], 0]) }));
|
|
36
44
|
};
|