@knapsack/adapter-core 4.92.15--canary.622247d.0 → 4.92.15
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.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mdx-processor.d.ts +12 -0
- package/dist/mdx-processor.d.ts.map +1 -0
- package/dist/mdx-processor.js +46 -0
- package/dist/mdx-processor.js.map +1 -0
- package/dist/mdx-table.d.ts +43 -0
- package/dist/mdx-table.d.ts.map +1 -0
- package/dist/mdx-table.js +154 -0
- package/dist/mdx-table.js.map +1 -0
- package/package.json +12 -5
package/dist/index.d.ts
CHANGED
|
@@ -15,4 +15,7 @@ export { sourceTag, tagFilenameForEntity } from './entity-filename.js';
|
|
|
15
15
|
export { contentHash } from './entity-hash.js';
|
|
16
16
|
export type { ComponentEntityFrontmatter, DocumentEntityFrontmatter, EntityFrontmatter, } from './entity-frontmatter.js';
|
|
17
17
|
export { buildEntityFrontmatter } from './entity-frontmatter.js';
|
|
18
|
+
export { getSharedProcessor } from './mdx-processor.js';
|
|
19
|
+
export type { TableNode, ParseTableOptions } from './mdx-table.js';
|
|
20
|
+
export { parseTable, canonicalizeTable, tableNodeToMarkdown, rowKeyNorm, } from './mdx-table.js';
|
|
18
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EAEV,UAAU,EACV,UAAU,EACV,gBAAgB,EAEhB,aAAa,EAEb,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAEhB,aAAa,EACb,WAAW,EACX,SAAS,EAET,SAAS,EACT,eAAe,EACf,cAAc,EACd,WAAW,EACX,YAAY,EAEZ,aAAa,EAEb,cAAc,EAEd,YAAY,EAC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AM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,YAAY,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,GACX,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,4 +13,7 @@ export { sourceTag, tagFilenameForEntity } from './entity-filename.js';
|
|
|
13
13
|
// Entity content hashing
|
|
14
14
|
export { contentHash } from './entity-hash.js';
|
|
15
15
|
export { buildEntityFrontmatter } from './entity-frontmatter.js';
|
|
16
|
+
// Shared MDX processor (remark-parse + remark-gfm + remark-mdx)
|
|
17
|
+
export { getSharedProcessor } from './mdx-processor.js';
|
|
18
|
+
export { parseTable, canonicalizeTable, tableNodeToMarkdown, rowKeyNorm, } from './mdx-table.js';
|
|
16
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAgBhD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,uBAAuB;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,yDAAyD;AACzD,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEvE,yBAAyB;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAgBhD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,uBAAuB;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,yDAAyD;AACzD,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEvE,yBAAyB;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,gEAAgE;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAIxD,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,GACX,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared unified processor for markdown/MDX parsing across all adapters.
|
|
3
|
+
* Provides remark-parse + remark-gfm + remark-mdx + remark-stringify.
|
|
4
|
+
*
|
|
5
|
+
* Lazy singleton — created once on first use.
|
|
6
|
+
*/
|
|
7
|
+
import type { Processor } from 'unified';
|
|
8
|
+
/**
|
|
9
|
+
* Returns the shared markdown/MDX processor. Created lazily on first use.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSharedProcessor(): Processor;
|
|
12
|
+
//# sourceMappingURL=mdx-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx-processor.d.ts","sourceRoot":"","sources":["../src/mdx-processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAyCzC;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,SAAS,CAK9C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared unified processor for markdown/MDX parsing across all adapters.
|
|
3
|
+
* Provides remark-parse + remark-gfm + remark-mdx + remark-stringify.
|
|
4
|
+
*
|
|
5
|
+
* Lazy singleton — created once on first use.
|
|
6
|
+
*/
|
|
7
|
+
import { unified } from 'unified';
|
|
8
|
+
import remarkParse from 'remark-parse';
|
|
9
|
+
import remarkGfm from 'remark-gfm';
|
|
10
|
+
import remarkMdx from 'remark-mdx';
|
|
11
|
+
import remarkStringify from 'remark-stringify';
|
|
12
|
+
let processor = null;
|
|
13
|
+
function createProcessor() {
|
|
14
|
+
const p = unified()
|
|
15
|
+
.use(remarkParse)
|
|
16
|
+
.use(remarkGfm)
|
|
17
|
+
.use(remarkMdx)
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- unified vs remark-stringify typings
|
|
19
|
+
.use(remarkStringify, {
|
|
20
|
+
bullet: '-',
|
|
21
|
+
fence: '`',
|
|
22
|
+
fences: true,
|
|
23
|
+
listItemIndent: 'one',
|
|
24
|
+
rule: '-',
|
|
25
|
+
emphasis: '_',
|
|
26
|
+
strong: '*',
|
|
27
|
+
});
|
|
28
|
+
// Validate by parsing so misconfiguration fails at startup.
|
|
29
|
+
try {
|
|
30
|
+
p.parse('');
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw new Error(`Shared markdown processor could not parse after applying remark-parse: ${err instanceof Error ? err.message : String(err)}`);
|
|
34
|
+
}
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the shared markdown/MDX processor. Created lazily on first use.
|
|
39
|
+
*/
|
|
40
|
+
export function getSharedProcessor() {
|
|
41
|
+
if (!processor) {
|
|
42
|
+
processor = createProcessor();
|
|
43
|
+
}
|
|
44
|
+
return processor;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=mdx-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx-processor.js","sourceRoot":"","sources":["../src/mdx-processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAI/C,IAAI,SAAS,GAAqB,IAAI,CAAC;AAEvC,SAAS,eAAe;IACtB,MAAM,CAAC,GAAG,OAAO,EAAE;SAChB,GAAG,CAAC,WAAqB,CAAC;SAC1B,GAAG,CAAC,SAAmB,CAAC;SACxB,GAAG,CAAC,SAAmB,CAAC;QACzB,qGAAqG;SACpG,GAAG,CAAC,eAAsB,EAAE;QAC3B,MAAM,EAAE,GAAG;QACX,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,IAAI;QACZ,cAAc,EAAE,KAAK;QACrB,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,GAAG;QACb,MAAM,EAAE,GAAG;KACZ,CAAC,CAAC;IAEL,4DAA4D;IAC5D,IAAI,CAAC;QACH,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,0EACE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CACjD,EAAE,CACH,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,eAAe,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and serialize markdown pipe tables into a stable structural form.
|
|
3
|
+
* Used by any adapter or conflict detector that needs to read/write/compare tables.
|
|
4
|
+
*
|
|
5
|
+
* Uses the shared unified processor (remark-parse + remark-gfm) for AST-based parsing.
|
|
6
|
+
*/
|
|
7
|
+
/** Parsed table: sorted column names, key column (first header), and rows as records. */
|
|
8
|
+
export type TableNode = {
|
|
9
|
+
/** Column names in stable order (sorted for canonical form). */
|
|
10
|
+
columns: string[];
|
|
11
|
+
/** Row identity = value of this column (first column in header order). */
|
|
12
|
+
keyColumn: string;
|
|
13
|
+
/** Rows keyed by column name. */
|
|
14
|
+
rows: Array<Record<string, string>>;
|
|
15
|
+
};
|
|
16
|
+
/** Options for parseTable. All optional; no limits by default. */
|
|
17
|
+
export interface ParseTableOptions {
|
|
18
|
+
/** When true, body rows with a different cell count than the header are skipped. Default: false. */
|
|
19
|
+
strictColumnCount?: boolean;
|
|
20
|
+
/** Cap the number of body rows parsed. Omitted = no limit. */
|
|
21
|
+
maxRows?: number;
|
|
22
|
+
/** Truncate cell values to this length. Omitted = no limit. */
|
|
23
|
+
maxCellLength?: number;
|
|
24
|
+
}
|
|
25
|
+
/** Normalize row key for comparison and hashing (trim + lowercase). */
|
|
26
|
+
export declare function rowKeyNorm(v: unknown): string;
|
|
27
|
+
/**
|
|
28
|
+
* Parse the first markdown pipe table in raw into a table node.
|
|
29
|
+
* Row identity = first column value. Returns null if no valid table.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseTable(raw: string, options?: ParseTableOptions): TableNode | null;
|
|
32
|
+
/**
|
|
33
|
+
* Stable canonical JSON string for hashing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function canonicalizeTable(node: TableNode): string;
|
|
36
|
+
/**
|
|
37
|
+
* Serialize a TableNode to a markdown pipe table string.
|
|
38
|
+
*
|
|
39
|
+
* @param table - The table to serialize.
|
|
40
|
+
* @param columnOrder - Optional column order override. When omitted, uses table.columns (sorted canonical order).
|
|
41
|
+
*/
|
|
42
|
+
export declare function tableNodeToMarkdown(table: TableNode, columnOrder?: readonly string[]): string;
|
|
43
|
+
//# sourceMappingURL=mdx-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx-table.d.ts","sourceRoot":"","sources":["../src/mdx-table.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH,yFAAyF;AACzF,MAAM,MAAM,SAAS,GAAG;IACtB,gEAAgE;IAChE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrC,CAAC;AAEF,kEAAkE;AAClE,MAAM,WAAW,iBAAiB;IAChC,oGAAoG;IACpG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAsBD,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAI7C;AAYD;;;GAGG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,iBAAiB,GAC1B,SAAS,GAAG,IAAI,CA8ElB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAezD;AAOD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,EAChB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,GAC9B,MAAM,CAOR"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and serialize markdown pipe tables into a stable structural form.
|
|
3
|
+
* Used by any adapter or conflict detector that needs to read/write/compare tables.
|
|
4
|
+
*
|
|
5
|
+
* Uses the shared unified processor (remark-parse + remark-gfm) for AST-based parsing.
|
|
6
|
+
*/
|
|
7
|
+
import { toString } from 'mdast-util-to-string';
|
|
8
|
+
import { EXIT, visit } from 'unist-util-visit';
|
|
9
|
+
import { getSharedProcessor } from './mdx-processor.js';
|
|
10
|
+
import { unified } from 'unified';
|
|
11
|
+
import remarkParse from 'remark-parse';
|
|
12
|
+
import remarkGfm from 'remark-gfm';
|
|
13
|
+
/**
|
|
14
|
+
* Minimal processor for table parsing: remark-parse + remark-gfm only.
|
|
15
|
+
* No remark-mdx — avoids JSX parsing that breaks on angle brackets in
|
|
16
|
+
* type names like `Array<Foo>`, `Omit<T, K>`, etc.
|
|
17
|
+
*/
|
|
18
|
+
let tableProcessor = null;
|
|
19
|
+
function getTableProcessor() {
|
|
20
|
+
if (!tableProcessor) {
|
|
21
|
+
tableProcessor = unified()
|
|
22
|
+
.use(remarkParse)
|
|
23
|
+
.use(remarkGfm);
|
|
24
|
+
}
|
|
25
|
+
return tableProcessor;
|
|
26
|
+
}
|
|
27
|
+
function norm(s) {
|
|
28
|
+
return s.trim();
|
|
29
|
+
}
|
|
30
|
+
/** Normalize row key for comparison and hashing (trim + lowercase). */
|
|
31
|
+
export function rowKeyNorm(v) {
|
|
32
|
+
return String(v ?? '')
|
|
33
|
+
.trim()
|
|
34
|
+
.toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
function dedupeHeaders(headers) {
|
|
37
|
+
const seen = new Map();
|
|
38
|
+
return headers.map((h) => {
|
|
39
|
+
const base = norm(h);
|
|
40
|
+
const n = (seen.get(base) ?? 0) + 1;
|
|
41
|
+
seen.set(base, n);
|
|
42
|
+
return n === 1 ? base : `${base}__${n}`;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse the first markdown pipe table in raw into a table node.
|
|
47
|
+
* Row identity = first column value. Returns null if no valid table.
|
|
48
|
+
*/
|
|
49
|
+
export function parseTable(raw, options) {
|
|
50
|
+
// Cascade: try GFM-only first (handles 95% of tables including angle brackets
|
|
51
|
+
// in type names like Array<Foo>), fall back to full MDX processor for
|
|
52
|
+
// MDX-embedded tables.
|
|
53
|
+
let tree = null;
|
|
54
|
+
for (const processor of [getTableProcessor(), getSharedProcessor()]) {
|
|
55
|
+
try {
|
|
56
|
+
tree = processor.parse(raw);
|
|
57
|
+
// Validate: must contain at least one table node
|
|
58
|
+
let hasTable = false;
|
|
59
|
+
visit(tree, 'table', () => {
|
|
60
|
+
hasTable = true;
|
|
61
|
+
return EXIT;
|
|
62
|
+
});
|
|
63
|
+
if (hasTable)
|
|
64
|
+
break;
|
|
65
|
+
tree = null;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!tree)
|
|
72
|
+
return null;
|
|
73
|
+
let firstTable = null;
|
|
74
|
+
visit(tree, 'table', (node) => {
|
|
75
|
+
firstTable = node;
|
|
76
|
+
return EXIT;
|
|
77
|
+
});
|
|
78
|
+
if (!firstTable)
|
|
79
|
+
return null;
|
|
80
|
+
const table = firstTable;
|
|
81
|
+
const tableChildren = table.children ?? [];
|
|
82
|
+
const [headerRow, ...bodyRows] = tableChildren;
|
|
83
|
+
if (!headerRow?.children?.length)
|
|
84
|
+
return null;
|
|
85
|
+
if (bodyRows.length === 0)
|
|
86
|
+
return null;
|
|
87
|
+
const headerCellsSource = headerRow.children ?? [];
|
|
88
|
+
let headerCells = headerCellsSource.map((c) => norm(toString(c)));
|
|
89
|
+
if (headerCells.some((h) => !h))
|
|
90
|
+
return null;
|
|
91
|
+
headerCells = dedupeHeaders(headerCells);
|
|
92
|
+
const keyColumn = headerCells[0];
|
|
93
|
+
if (!keyColumn)
|
|
94
|
+
return null;
|
|
95
|
+
const columns = [...headerCells].sort((a, b) => a.localeCompare(b));
|
|
96
|
+
const strictColumnCount = options?.strictColumnCount ?? false;
|
|
97
|
+
const maxRows = options?.maxRows;
|
|
98
|
+
const maxCellLength = options?.maxCellLength;
|
|
99
|
+
const rows = [];
|
|
100
|
+
for (const r of bodyRows) {
|
|
101
|
+
if (maxRows != null && rows.length >= maxRows)
|
|
102
|
+
break;
|
|
103
|
+
let cells = (r?.children ?? []).map((c) => norm(toString(c)));
|
|
104
|
+
if (strictColumnCount && cells.length !== headerCells.length)
|
|
105
|
+
continue;
|
|
106
|
+
if (maxCellLength != null) {
|
|
107
|
+
cells = cells.map((cell) => cell.length <= maxCellLength ? cell : cell.slice(0, maxCellLength));
|
|
108
|
+
}
|
|
109
|
+
const obj = {};
|
|
110
|
+
for (let i = 0; i < headerCells.length; i++) {
|
|
111
|
+
obj[headerCells[i]] = cells[i] ?? '';
|
|
112
|
+
}
|
|
113
|
+
if (Object.values(obj).some((v) => v !== ''))
|
|
114
|
+
rows.push(obj);
|
|
115
|
+
}
|
|
116
|
+
rows.sort((a, b) => rowKeyNorm(a[keyColumn]).localeCompare(rowKeyNorm(b[keyColumn])));
|
|
117
|
+
return { columns, keyColumn, rows };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Stable canonical JSON string for hashing.
|
|
121
|
+
*/
|
|
122
|
+
export function canonicalizeTable(node) {
|
|
123
|
+
const keyCol = node.keyColumn;
|
|
124
|
+
const canonical = {
|
|
125
|
+
columns: node.columns,
|
|
126
|
+
keyColumn: keyCol,
|
|
127
|
+
rows: node.rows.map((row) => {
|
|
128
|
+
const keys = Object.keys(row).sort((a, b) => a.localeCompare(b));
|
|
129
|
+
const out = {};
|
|
130
|
+
for (const k of keys) {
|
|
131
|
+
out[k] = k === keyCol ? rowKeyNorm(row[k]) : (row[k] ?? '');
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
return JSON.stringify(canonical);
|
|
137
|
+
}
|
|
138
|
+
/** Escape literal pipe characters inside a cell value so they don't break table structure. */
|
|
139
|
+
function escapeCell(value) {
|
|
140
|
+
return value.replace(/\|/g, '\\|');
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Serialize a TableNode to a markdown pipe table string.
|
|
144
|
+
*
|
|
145
|
+
* @param table - The table to serialize.
|
|
146
|
+
* @param columnOrder - Optional column order override. When omitted, uses table.columns (sorted canonical order).
|
|
147
|
+
*/
|
|
148
|
+
export function tableNodeToMarkdown(table, columnOrder) {
|
|
149
|
+
const headers = columnOrder ?? table.columns;
|
|
150
|
+
const separator = headers.map(() => '---').join(' | ');
|
|
151
|
+
const rows = table.rows.map((row) => headers.map((h) => escapeCell(row[h] ?? '')).join(' | '));
|
|
152
|
+
return [headers.join(' | '), separator, ...rows].join('\n');
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=mdx-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx-table.js","sourceRoot":"","sources":["../src/mdx-table.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;AAoCnC;;;;GAIG;AACH,IAAI,cAAc,GAAsC,IAAI,CAAC;AAE7D,SAAS,iBAAiB;IACxB,IAAI,CAAC,cAAc,EAAE,CAAC;QACp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,EAAE,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;KACH,CAAC;IACF,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,8FAA8F;AAC9F,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAgB,EAChB,WAA+B;IAE/B,MAAM,OAAO,GAAG,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC;IAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAClC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CACzD,CAAC;IACF,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knapsack/adapter-core",
|
|
3
3
|
"description": "Core types, interfaces, and logging for ContextSrcAdapters",
|
|
4
|
-
"version": "4.92.15
|
|
4
|
+
"version": "4.92.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -22,12 +22,19 @@
|
|
|
22
22
|
},
|
|
23
23
|
"author": "Knapsack (https://www.knapsack.cloud)",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@knapsack/logger": "4.92.15
|
|
25
|
+
"@knapsack/logger": "4.92.15",
|
|
26
|
+
"mdast-util-to-string": "^4.0.0",
|
|
27
|
+
"remark-gfm": "^4.0.1",
|
|
28
|
+
"remark-mdx": "^3.1.1",
|
|
29
|
+
"remark-parse": "^11.0.0",
|
|
30
|
+
"remark-stringify": "^11.0.0",
|
|
31
|
+
"unified": "^11.0.0",
|
|
32
|
+
"unist-util-visit": "^5.0.0",
|
|
26
33
|
"yaml": "^2.8.3"
|
|
27
34
|
},
|
|
28
35
|
"devDependencies": {
|
|
29
|
-
"@knapsack/eslint-config-starter": "4.92.15
|
|
30
|
-
"@knapsack/typescript-config-starter": "4.92.15
|
|
36
|
+
"@knapsack/eslint-config-starter": "4.92.15",
|
|
37
|
+
"@knapsack/typescript-config-starter": "4.92.15",
|
|
31
38
|
"@types/node": "^22.19.11",
|
|
32
39
|
"eslint": "^9.20.0",
|
|
33
40
|
"typescript": "^5.9.3"
|
|
@@ -41,5 +48,5 @@
|
|
|
41
48
|
"directory": "libs/ingest-pipeline/adapters/core",
|
|
42
49
|
"type": "git"
|
|
43
50
|
},
|
|
44
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "609106b8e3e2d8e3e164b6437ad083198941f463"
|
|
45
52
|
}
|