@cudoment/cudoc 0.4.0 → 0.5.0
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/README.md +1 -1
- package/dist/document.d.ts +11 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +33 -2
- package/dist/document.js.map +1 -1
- package/dist/internal/core/mdx/imports.d.ts +21 -0
- package/dist/internal/core/mdx/imports.d.ts.map +1 -0
- package/dist/internal/core/mdx/imports.js +80 -0
- package/dist/internal/core/mdx/imports.js.map +1 -0
- package/dist/internal/core/mdx/index.d.ts +1 -0
- package/dist/internal/core/mdx/index.d.ts.map +1 -1
- package/dist/internal/core/mdx/index.js +1 -0
- package/dist/internal/core/mdx/index.js.map +1 -1
- package/dist/internal/transforms/table-column-layout/create-table.d.ts.map +1 -1
- package/dist/internal/transforms/table-column-layout/create-table.js +40 -17
- package/dist/internal/transforms/table-column-layout/create-table.js.map +1 -1
- package/dist/internal/transforms/table-column-layout/index.d.ts +32 -0
- package/dist/internal/transforms/table-column-layout/index.d.ts.map +1 -1
- package/dist/internal/transforms/table-column-layout/index.js +66 -0
- package/dist/internal/transforms/table-column-layout/index.js.map +1 -1
- package/dist/markdown.d.ts +8 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +9 -1
- package/dist/markdown.js.map +1 -1
- package/dist/node/check.d.ts +6 -3
- package/dist/node/check.d.ts.map +1 -1
- package/dist/node/check.js +101 -23
- package/dist/node/check.js.map +1 -1
- package/dist/node/cli.js +26 -1
- package/dist/node/cli.js.map +1 -1
- package/dist/node/dataset.d.ts +14 -1
- package/dist/node/dataset.d.ts.map +1 -1
- package/dist/node/dataset.js +40 -4
- package/dist/node/dataset.js.map +1 -1
- package/dist/node/glob.d.ts +21 -0
- package/dist/node/glob.d.ts.map +1 -0
- package/dist/node/glob.js +61 -0
- package/dist/node/glob.js.map +1 -0
- package/dist/node/library.d.ts +70 -4
- package/dist/node/library.d.ts.map +1 -1
- package/dist/node/library.js +196 -32
- package/dist/node/library.js.map +1 -1
- package/dist/node/local-target.d.ts +28 -8
- package/dist/node/local-target.d.ts.map +1 -1
- package/dist/node/local-target.js +41 -12
- package/dist/node/local-target.js.map +1 -1
- package/dist/node/prepare-embeds.d.ts +16 -2
- package/dist/node/prepare-embeds.d.ts.map +1 -1
- package/dist/node/prepare-embeds.js +41 -5
- package/dist/node/prepare-embeds.js.map +1 -1
- package/dist/node/resolve-embed.d.ts +79 -1
- package/dist/node/resolve-embed.d.ts.map +1 -1
- package/dist/node/resolve-embed.js +251 -43
- package/dist/node/resolve-embed.js.map +1 -1
- package/dist/node/roots.d.ts +67 -0
- package/dist/node/roots.d.ts.map +1 -0
- package/dist/node/roots.js +134 -0
- package/dist/node/roots.js.map +1 -0
- package/dist/node/storage.d.ts +21 -3
- package/dist/node/storage.d.ts.map +1 -1
- package/dist/node/storage.js +41 -12
- package/dist/node/storage.js.map +1 -1
- package/dist/node/watch.d.ts +81 -0
- package/dist/node/watch.d.ts.map +1 -0
- package/dist/node/watch.js +140 -0
- package/dist/node/watch.js.map +1 -0
- package/dist/paged.d.ts +34 -0
- package/dist/paged.d.ts.map +1 -0
- package/dist/paged.js +44 -0
- package/dist/paged.js.map +1 -0
- package/package.json +15 -2
- package/styles.css +5 -2
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { safePath } from "./storage.js";
|
|
11
|
+
import { candidateFiles } from "./roots.js";
|
|
11
12
|
/** `safePath`, but a path escaping its root is a non-match rather than a throw. */
|
|
12
13
|
const containedPath = (root, relative) => {
|
|
13
14
|
try {
|
|
@@ -17,18 +18,35 @@ const containedPath = (root, relative) => {
|
|
|
17
18
|
return undefined;
|
|
18
19
|
}
|
|
19
20
|
};
|
|
21
|
+
/** A fragment, a scheme or a protocol-relative URL: nothing on this disk. */
|
|
22
|
+
export const externalUrl = (url) => /^(?:#|[a-z][\w+.-]*:|\/\/)/i.test(url);
|
|
23
|
+
/**
|
|
24
|
+
* Whether a root-relative URL falls under one of the configured external
|
|
25
|
+
* prefixes. `/sdk` covers `/sdk` and `/sdk/…`, not `/sdk-tools`.
|
|
26
|
+
*/
|
|
27
|
+
export function isExternalPath(url, prefixes) {
|
|
28
|
+
if (!prefixes?.length || !url.startsWith("/") || url.startsWith("//"))
|
|
29
|
+
return false;
|
|
30
|
+
const pathname = url.match(/^[^?#]*/)[0];
|
|
31
|
+
return prefixes.some((prefix) => {
|
|
32
|
+
const clean = `/${prefix.replace(/^\/+|\/+$/g, "")}`;
|
|
33
|
+
return (clean !== "/" && (pathname === clean || pathname.startsWith(`${clean}/`)));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
20
36
|
/**
|
|
21
37
|
* Resolves one URL against the document that carries it.
|
|
22
38
|
*
|
|
23
|
-
* A fragment, scheme or protocol-relative URL is external and left alone
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
39
|
+
* A fragment, scheme or protocol-relative URL is external and left alone, and
|
|
40
|
+
* so is a root-relative one under an external prefix. A document-relative
|
|
41
|
+
* path resolves against the library path of its document, and a root-relative
|
|
42
|
+
* one against the library itself; both then reach disk through the roots. A
|
|
43
|
+
* root-relative path is also tried against each asset directory, after the
|
|
44
|
+
* deployment base is removed. A path that escapes every root is reported as
|
|
45
|
+
* missing rather than resolved, so the caller names the link and its document
|
|
46
|
+
* instead of a traversal that means nothing to an author.
|
|
29
47
|
*/
|
|
30
48
|
export function resolveLocalTarget(url, documentSourcePath, roots) {
|
|
31
|
-
if (
|
|
49
|
+
if (externalUrl(url) || isExternalPath(url, roots.externalPaths))
|
|
32
50
|
return { kind: "external", url };
|
|
33
51
|
const [, pathname, suffix] = url.match(/^([^?#]*)(.*)$/);
|
|
34
52
|
const decoded = decodeURIComponent(pathname);
|
|
@@ -38,14 +56,25 @@ export function resolveLocalTarget(url, documentSourcePath, roots) {
|
|
|
38
56
|
const withoutBase = roots.withoutBase ?? ((value) => value);
|
|
39
57
|
const rootPath = withoutBase(decoded.startsWith("/") ? decoded : `/${relative}`).replace(/^\//, "");
|
|
40
58
|
const candidates = [
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
...candidateFiles(roots.roots, relative).map((source) => ({
|
|
60
|
+
relative,
|
|
61
|
+
source,
|
|
62
|
+
})),
|
|
63
|
+
...(roots.assetDirs ?? []).flatMap((root) => {
|
|
64
|
+
const source = containedPath(root, rootPath);
|
|
65
|
+
return source ? [{ relative: rootPath, source }] : [];
|
|
66
|
+
}),
|
|
43
67
|
];
|
|
44
68
|
for (const candidate of candidates) {
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
if (!fs.existsSync(candidate.source) ||
|
|
70
|
+
!fs.statSync(candidate.source).isFile())
|
|
47
71
|
continue;
|
|
48
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
kind: "resolved",
|
|
74
|
+
relative: candidate.relative,
|
|
75
|
+
source: candidate.source,
|
|
76
|
+
suffix,
|
|
77
|
+
};
|
|
49
78
|
}
|
|
50
79
|
return { kind: "missing", relative, suffix };
|
|
51
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-target.js","sourceRoot":"","sources":["../../src/node/local-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"local-target.js","sourceRoot":"","sources":["../../src/node/local-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,cAAc,EAAqB,MAAM,YAAY,CAAA;AA6B9D,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MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IACE,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC;YAChC,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE;YAEvC,SAAQ;QACV,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,MAAM;SACP,CAAA;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;AAC9C,CAAC"}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import type { Root } from "mdast";
|
|
2
2
|
import type { Library } from "./library.js";
|
|
3
3
|
export type PreparedEmbeds = {
|
|
4
|
-
schemaVersion:
|
|
4
|
+
schemaVersion: 2;
|
|
5
5
|
configuration: string;
|
|
6
6
|
sourceHashes: Record<string, string>;
|
|
7
7
|
blocks: Record<string, Root>;
|
|
8
|
+
/**
|
|
9
|
+
* The documents each block read, by block key: the sources named in its
|
|
10
|
+
* fence and in every embed nested in them. `["*"]` marks a block that ran
|
|
11
|
+
* an extractor, which may read anything.
|
|
12
|
+
*/
|
|
13
|
+
dependencies: Record<string, string[]>;
|
|
8
14
|
};
|
|
9
15
|
export declare const embedKey: (documentId: string, value: string, index: number) => string;
|
|
16
|
+
export type PrepareEmbedsOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* The result of an earlier preparation. A block is taken from it unresolved
|
|
19
|
+
* when the configuration, the set of documents, the embedding document and
|
|
20
|
+
* every document the block depends on are unchanged.
|
|
21
|
+
*/
|
|
22
|
+
previous?: PreparedEmbeds;
|
|
23
|
+
};
|
|
10
24
|
/** Run after collection and before the host build. No asynchronous compiler is needed at render time. */
|
|
11
|
-
export declare function prepareEmbeds(library: Library, outDir?: string): Promise<PreparedEmbeds>;
|
|
25
|
+
export declare function prepareEmbeds(library: Library, outDir?: string, options?: PrepareEmbedsOptions): Promise<PreparedEmbeds>;
|
|
12
26
|
export declare function readPreparedEmbeds(outDir: string, documentId: string, source: string): PreparedEmbeds;
|
|
13
27
|
//# sourceMappingURL=prepare-embeds.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-embeds.d.ts","sourceRoot":"","sources":["../../src/node/prepare-embeds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,CAAC,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"prepare-embeds.d.ts","sourceRoot":"","sources":["../../src/node/prepare-embeds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,CAAC,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC5B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CACvC,CAAA;AACD,eAAO,MAAM,QAAQ,GAAI,YAAY,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,MAAM,WAChC,CAAA;AAEzC,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAA;CAC1B,CAAA;AAyBD,yGAAyG;AACzG,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,MAAM,SAAqB,EAC3B,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,cAAc,CAAC,CA4DzB;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,cAAc,CAuBhB"}
|
|
@@ -2,23 +2,59 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { hash } from "./storage.js";
|
|
4
4
|
export const embedKey = (documentId, value, index) => `${documentId}:${index}:${hash(value)}`;
|
|
5
|
+
/**
|
|
6
|
+
* Whether blocks may be taken from a previous preparation at all: the same
|
|
7
|
+
* configuration and the same set of documents. A document added or removed
|
|
8
|
+
* changes what links inside any block resolve to, so nothing is reused then.
|
|
9
|
+
*/
|
|
10
|
+
const reusableBlocks = (library, previous) => {
|
|
11
|
+
if (!previous ||
|
|
12
|
+
previous.schemaVersion !== 2 ||
|
|
13
|
+
previous.configuration !== library.configuration ||
|
|
14
|
+
typeof previous.dependencies !== "object")
|
|
15
|
+
return undefined;
|
|
16
|
+
const ids = library.documents.map((document) => document.id).sort();
|
|
17
|
+
const known = Object.keys(previous.sourceHashes).sort();
|
|
18
|
+
if (ids.length !== known.length || ids.some((id, i) => id !== known[i]))
|
|
19
|
+
return undefined;
|
|
20
|
+
return previous;
|
|
21
|
+
};
|
|
5
22
|
/** Run after collection and before the host build. No asynchronous compiler is needed at render time. */
|
|
6
|
-
export async function prepareEmbeds(library, outDir = ".cudoc/documents") {
|
|
23
|
+
export async function prepareEmbeds(library, outDir = ".cudoc/documents", options = {}) {
|
|
7
24
|
const { resolveEmbedAsync, parseEmbedBlock } = await import("./resolve-embed.js");
|
|
8
25
|
const prepared = {
|
|
9
|
-
schemaVersion:
|
|
26
|
+
schemaVersion: 2,
|
|
10
27
|
configuration: library.configuration,
|
|
11
28
|
sourceHashes: {},
|
|
12
29
|
blocks: {},
|
|
30
|
+
dependencies: {},
|
|
13
31
|
};
|
|
32
|
+
const previous = reusableBlocks(library, options.previous);
|
|
33
|
+
const hashes = new Map(library.documents.map((document) => [document.id, document.source.hash]));
|
|
34
|
+
const unchanged = (id) => previous !== undefined && previous.sourceHashes[id] === hashes.get(id);
|
|
14
35
|
for (const document of library.documents) {
|
|
15
36
|
prepared.sourceHashes[document.id] = document.source.hash;
|
|
16
37
|
let index = 0;
|
|
17
38
|
const collect = async (node) => {
|
|
18
39
|
if (node.type === "code" && node.lang === "cudoc-embed") {
|
|
19
40
|
const number = ++index;
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
const key = embedKey(document.id, node.value, number);
|
|
42
|
+
const stored = previous?.blocks[key];
|
|
43
|
+
const dependencies = previous?.dependencies[key];
|
|
44
|
+
if (stored &&
|
|
45
|
+
dependencies &&
|
|
46
|
+
unchanged(document.id) &&
|
|
47
|
+
!dependencies.includes("*") &&
|
|
48
|
+
dependencies.every(unchanged)) {
|
|
49
|
+
prepared.blocks[key] = stored;
|
|
50
|
+
prepared.dependencies[key] = dependencies;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const result = await resolveEmbedAsync(library, parseEmbedBlock(node.value, document.id, number), { documentId: document.id, prefix: `embed-${number}` });
|
|
54
|
+
prepared.blocks[key] = result;
|
|
55
|
+
prepared.dependencies[key] = Array.isArray(result.data?.cudocDependencies)
|
|
56
|
+
? result.data.cudocDependencies
|
|
57
|
+
: ["*"];
|
|
22
58
|
}
|
|
23
59
|
for (const child of node.children ?? [])
|
|
24
60
|
await collect(child);
|
|
@@ -41,7 +77,7 @@ export function readPreparedEmbeds(outDir, documentId, source) {
|
|
|
41
77
|
throw new Error("cudoc: prepared embeds not found; collect documents and run prepareEmbeds before building the host");
|
|
42
78
|
const result = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
43
79
|
const manifest = JSON.parse(fs.readFileSync(path.join(outDir, "manifest.json"), "utf8"));
|
|
44
|
-
if (result.schemaVersion !==
|
|
80
|
+
if (result.schemaVersion !== 2 ||
|
|
45
81
|
result.configuration !== manifest.configuration ||
|
|
46
82
|
result.sourceHashes[documentId] !== hash(source) ||
|
|
47
83
|
manifest.documents.some((doc) => result.sourceHashes[doc.id] !== doc.hash))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-embeds.js","sourceRoot":"","sources":["../../src/node/prepare-embeds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAI5B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"prepare-embeds.js","sourceRoot":"","sources":["../../src/node/prepare-embeds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAI5B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAcnC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAAkB,EAAE,KAAa,EAAE,KAAa,EAAE,EAAE,CAC3E,GAAG,UAAU,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;AAWzC;;;;GAIG;AACH,MAAM,cAAc,GAAG,CACrB,OAAgB,EAChB,QAAoC,EACR,EAAE;IAC9B,IACE,CAAC,QAAQ;QACT,QAAQ,CAAC,aAAa,KAAK,CAAC;QAC5B,QAAQ,CAAC,aAAa,KAAK,OAAO,CAAC,aAAa;QAChD,OAAO,QAAQ,CAAC,YAAY,KAAK,QAAQ;QAEzC,OAAO,SAAS,CAAA;IAClB,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,C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AAK,CACzB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CAC5D,CAAA;IACD,IACE,MAAM,CAAC,aAAa,KAAK,CAAC;QAC1B,MAAM,CAAC,aAAa,KAAK,QAAQ,CAAC,aAAa;QAC/C,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC;QAChD,QAAQ,CAAC,SAAS,CAAC,IAAI,CACrB,CAAC,GAAiC,EAAE,EAAE,CACpC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,IAAI,CAC3C;QAED,MAAM,IAAI,KAAK,CACb,oCAAoC,UAAU,uBAAuB,CACtE,CAAA;IACH,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -7,12 +7,37 @@ export type Replacement = {
|
|
|
7
7
|
regex?: boolean;
|
|
8
8
|
flags?: string;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Where a table cell's text comes from.
|
|
12
|
+
*
|
|
13
|
+
* `title`, `summary` and `parent` read the row's section; the coordinate form
|
|
14
|
+
* reads one cell of one table inside it, counting tables after those whose
|
|
15
|
+
* header row names a heading in `skipTablesWithHeaders`; `extractor` names a
|
|
16
|
+
* function the collection config registered.
|
|
17
|
+
*/
|
|
18
|
+
export type CellValue = "title" | "summary" | "parent" | {
|
|
19
|
+
table?: number;
|
|
20
|
+
row: number;
|
|
21
|
+
column: number;
|
|
22
|
+
skipTablesWithHeaders?: string[];
|
|
23
|
+
} | {
|
|
24
|
+
extractor: string;
|
|
25
|
+
};
|
|
26
|
+
/** Where a cell links to: the row's section, the heading above it, or its document. */
|
|
27
|
+
export type CellLink = "section" | "parent" | "document";
|
|
28
|
+
export type TableColumn = "title" | "link" | "summary" | {
|
|
29
|
+
header?: string;
|
|
30
|
+
value: CellValue;
|
|
31
|
+
link?: CellLink;
|
|
32
|
+
/** A CSS length written onto the header cell's `style` as `min-width`. */
|
|
33
|
+
minWidth?: string;
|
|
34
|
+
};
|
|
10
35
|
export type EmbedSpec = {
|
|
11
36
|
sources: string[];
|
|
12
37
|
select?: SectionSelection;
|
|
13
38
|
render?: "section" | {
|
|
14
39
|
type: "table";
|
|
15
|
-
columns?:
|
|
40
|
+
columns?: TableColumn[];
|
|
16
41
|
};
|
|
17
42
|
replace?: Replacement[];
|
|
18
43
|
};
|
|
@@ -20,6 +45,40 @@ export type EmbedContext = {
|
|
|
20
45
|
documentId: string;
|
|
21
46
|
prefix?: string;
|
|
22
47
|
};
|
|
48
|
+
/** What a cell shows: text, and a link when the column or extractor gives one. */
|
|
49
|
+
export type ExtractedCell = {
|
|
50
|
+
text: string;
|
|
51
|
+
url?: string;
|
|
52
|
+
};
|
|
53
|
+
/** One row of an extracted table: the selected section and where it sits. */
|
|
54
|
+
export type EmbedRow = {
|
|
55
|
+
document: StoredDocument;
|
|
56
|
+
section: {
|
|
57
|
+
anchorId?: string;
|
|
58
|
+
title: string;
|
|
59
|
+
tree: Root;
|
|
60
|
+
};
|
|
61
|
+
/** The nearest heading above the section that is shallower than it. */
|
|
62
|
+
parent?: {
|
|
63
|
+
title: string;
|
|
64
|
+
anchorId?: string;
|
|
65
|
+
};
|
|
66
|
+
/** The row section's own address. */
|
|
67
|
+
url: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* A function the collection config registers to compute a cell. `version`
|
|
71
|
+
* enters the library configuration, so changing what the function returns
|
|
72
|
+
* for the same input invalidates prepared embeds.
|
|
73
|
+
*/
|
|
74
|
+
export type TableExtractor = {
|
|
75
|
+
version: string;
|
|
76
|
+
extract: (row: EmbedRow, context: {
|
|
77
|
+
library: Library;
|
|
78
|
+
documentId: string;
|
|
79
|
+
column: TableColumn;
|
|
80
|
+
}) => string | ExtractedCell | undefined;
|
|
81
|
+
};
|
|
23
82
|
export declare function parseEmbedSpec(value: string): EmbedSpec;
|
|
24
83
|
/**
|
|
25
84
|
* Parses one fenced block, naming the document and block when it fails.
|
|
@@ -34,6 +93,25 @@ export declare function resolveDocumentReference(library: Library, reference: st
|
|
|
34
93
|
document: StoredDocument;
|
|
35
94
|
anchor?: string;
|
|
36
95
|
};
|
|
96
|
+
/** The default columns of a summary table, as they have always been. */
|
|
97
|
+
export declare const DEFAULT_TABLE_COLUMNS: TableColumn[];
|
|
98
|
+
/**
|
|
99
|
+
* One row for a selected section: what it is called, where it lives and which
|
|
100
|
+
* heading introduces the part of the document it sits in.
|
|
101
|
+
*/
|
|
102
|
+
export declare function buildEmbedRow(document: StoredDocument, anchorId: string | undefined, tree: Root): EmbedRow;
|
|
103
|
+
/**
|
|
104
|
+
* The text and link one column shows for one row, and why it is empty when it
|
|
105
|
+
* is. The resolver renders the cell either way; the checker reports the
|
|
106
|
+
* problem, which is worded as what the column asked for and what the section
|
|
107
|
+
* has, so an author can tell a wrong coordinate from a missing table.
|
|
108
|
+
*/
|
|
109
|
+
export declare function extractCell(library: Library, column: TableColumn, row: EmbedRow, context: EmbedContext): {
|
|
110
|
+
cell: ExtractedCell;
|
|
111
|
+
problem?: string;
|
|
112
|
+
};
|
|
113
|
+
/** The mdast table the extracted cells make, header cells carrying any width. */
|
|
114
|
+
export declare function buildEmbedTable(library: Library, columns: TableColumn[], rows: EmbedRow[], context: EmbedContext): Root;
|
|
37
115
|
/** Resolve a configured embed from immutable persisted documents. */
|
|
38
116
|
export declare function resolveEmbed(library: Library, input: EmbedSpec, context: EmbedContext): Root;
|
|
39
117
|
export declare function resolveDocumentEmbeds(library: Library, documentId: string): Root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-embed.d.ts","sourceRoot":"","sources":["../../src/node/resolve-embed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAGjC,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"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