cudoc-remark 0.2.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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/capture.d.ts +10 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +33 -0
- package/dist/capture.js.map +1 -0
- package/dist/components/index.d.ts +37 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +13 -0
- package/dist/components/index.js.map +1 -0
- package/dist/embed.d.ts +9 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +74 -0
- package/dist/embed.js.map +1 -0
- package/dist/heading-ids.d.ts +26 -0
- package/dist/heading-ids.d.ts.map +1 -0
- package/dist/heading-ids.js +35 -0
- package/dist/heading-ids.js.map +1 -0
- package/dist/host-plugins.d.ts +18 -0
- package/dist/host-plugins.d.ts.map +1 -0
- package/dist/host-plugins.js +64 -0
- package/dist/host-plugins.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +52 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +88 -0
- package/dist/options.js.map +1 -0
- package/dist/prepare.d.ts +25 -0
- package/dist/prepare.d.ts.map +1 -0
- package/dist/prepare.js +115 -0
- package/dist/prepare.js.map +1 -0
- package/dist/runtime.d.ts +11 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +12 -0
- package/dist/runtime.js.map +1 -0
- package/dist/toc.d.ts +58 -0
- package/dist/toc.d.ts.map +1 -0
- package/dist/toc.js +126 -0
- package/dist/toc.js.map +1 -0
- package/dist/transforms/badge.d.ts +28 -0
- package/dist/transforms/badge.d.ts.map +1 -0
- package/dist/transforms/badge.js +58 -0
- package/dist/transforms/badge.js.map +1 -0
- package/dist/transforms/table-cell-list/build-table-cell-children.d.ts +2 -0
- package/dist/transforms/table-cell-list/build-table-cell-children.d.ts.map +1 -0
- package/dist/transforms/table-cell-list/build-table-cell-children.js +3 -0
- package/dist/transforms/table-cell-list/build-table-cell-children.js.map +1 -0
- package/dist/transforms/table-cell-list/elements.d.ts +2 -0
- package/dist/transforms/table-cell-list/elements.d.ts.map +1 -0
- package/dist/transforms/table-cell-list/elements.js +3 -0
- package/dist/transforms/table-cell-list/elements.js.map +1 -0
- package/dist/transforms/table-cell-list/index.d.ts +2 -0
- package/dist/transforms/table-cell-list/index.d.ts.map +1 -0
- package/dist/transforms/table-cell-list/index.js +3 -0
- package/dist/transforms/table-cell-list/index.js.map +1 -0
- package/dist/transforms/table-cell-list/nodes.d.ts +2 -0
- package/dist/transforms/table-cell-list/nodes.d.ts.map +1 -0
- package/dist/transforms/table-cell-list/nodes.js +3 -0
- package/dist/transforms/table-cell-list/nodes.js.map +1 -0
- package/dist/transforms/table-cell-list/parse-inline-markdown.d.ts +2 -0
- package/dist/transforms/table-cell-list/parse-inline-markdown.d.ts.map +1 -0
- package/dist/transforms/table-cell-list/parse-inline-markdown.js +3 -0
- package/dist/transforms/table-cell-list/parse-inline-markdown.js.map +1 -0
- package/dist/transforms/table-cell-list/parse-table-cell-list.d.ts +2 -0
- package/dist/transforms/table-cell-list/parse-table-cell-list.d.ts.map +1 -0
- package/dist/transforms/table-cell-list/parse-table-cell-list.js +3 -0
- package/dist/transforms/table-cell-list/parse-table-cell-list.js.map +1 -0
- package/dist/transforms/table-column-layout/create-table.d.ts +2 -0
- package/dist/transforms/table-column-layout/create-table.d.ts.map +1 -0
- package/dist/transforms/table-column-layout/create-table.js +3 -0
- package/dist/transforms/table-column-layout/create-table.js.map +1 -0
- package/dist/transforms/table-column-layout/index.d.ts +2 -0
- package/dist/transforms/table-column-layout/index.d.ts.map +1 -0
- package/dist/transforms/table-column-layout/index.js +3 -0
- package/dist/transforms/table-column-layout/index.js.map +1 -0
- package/dist/transforms/table-column-layout/split-cell.d.ts +2 -0
- package/dist/transforms/table-column-layout/split-cell.d.ts.map +1 -0
- package/dist/transforms/table-column-layout/split-cell.js +3 -0
- package/dist/transforms/table-column-layout/split-cell.js.map +1 -0
- package/package.json +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cudoment
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# cudoc-remark
|
|
2
|
+
|
|
3
|
+
Connect cudoc Markdown syntax and prepared document embeds to a remark/MDX pipeline.
|
|
4
|
+
|
|
5
|
+
This separate package is a pipeline adapter, not a second implementation of cudoc's rules. Shared document semantics live in `@cudoment/cudoc`. Use it directly with Next.js/remark; Docusaurus and Nextra adapters already depend on it. VitePress and HTML use their own adapters and do not need this plugin.
|
|
6
|
+
|
|
7
|
+
ESM · Node.js 20+
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @cudoment/cudoc cudoc-remark remark-gfm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import remarkGfm from "remark-gfm"
|
|
15
|
+
import cudoc from "cudoc-remark"
|
|
16
|
+
|
|
17
|
+
const remarkPlugins = [remarkGfm, [cudoc, { host: "next", syntax: {} }]]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Default settings produce component-free output in both `.md` and `.mdx`; `syntax: {}` makes the defaults explicit. Let the host detect the document format. For Next.js Turbopack, use package-name plugin strings and JSON options as shown in the guide. `cudoc-remark/embed` inserts its runtime automatically after collection and preparation.
|
|
21
|
+
|
|
22
|
+
Choose `host`, `cudoc` or `both` independently for `headingAnchor`, `badge`, `tableCellList`, `callout` and `link`. The representative callout is `> [!NOTE] Title`. Authors do not register cudoc React components in the recommended setup. Syntax-only rendering needs no stored JSON; cross-document embedding requires document collection.
|
|
23
|
+
|
|
24
|
+
- [Usage guide](https://github.com/cudoment/cudoc/tree/main/docs/next-mdx.md) · [한국어 가이드](https://github.com/cudoment/cudoc/tree/main/docs/next-mdx.ko.md)
|
|
25
|
+
- [Markdown syntax](https://github.com/cudoment/cudoc/tree/main/docs/syntax.md)
|
|
26
|
+
- [Embedding](https://github.com/cudoment/cudoc/tree/main/docs/embedding.md)
|
|
27
|
+
- [Standalone HTML alongside a host](https://github.com/cudoment/cudoc/tree/main/docs/html.md#export-alongside-an-existing-site)
|
|
28
|
+
- [API reference](https://github.com/cudoment/cudoc/tree/main/docs/api-reference/README.md)
|
|
29
|
+
- [Runnable examples](https://github.com/cudoment/cudoc/tree/main/examples/README.md)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Root } from "mdast";
|
|
2
|
+
import type { Plugin } from "unified";
|
|
3
|
+
import type { CompiledDocument } from "@cudoment/cudoc/markdown";
|
|
4
|
+
/** Capture remark's final tree at the start of rehype, after native host plugins. */
|
|
5
|
+
export declare function createCompilerCapture(): {
|
|
6
|
+
remark: Plugin<[], Root>;
|
|
7
|
+
rehype: Plugin;
|
|
8
|
+
read(): CompiledDocument;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,qFAAqF;AACrF,wBAAgB,qBAAqB;;;YAyBzB,gBAAgB;EAQ3B"}
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { lowerNativeElements } from "@cudoment/cudoc/document";
|
|
2
|
+
/** Capture remark's final tree at the start of rehype, after native host plugins. */
|
|
3
|
+
export function createCompilerCapture() {
|
|
4
|
+
let current;
|
|
5
|
+
let result;
|
|
6
|
+
const remark = () => (tree) => {
|
|
7
|
+
current = tree;
|
|
8
|
+
};
|
|
9
|
+
const rehype = () => (_tree, file) => {
|
|
10
|
+
if (!current)
|
|
11
|
+
throw new Error("cudoc: install capture.remark before capture.rehype");
|
|
12
|
+
const tree = structuredClone(current);
|
|
13
|
+
lowerNativeElements(tree);
|
|
14
|
+
tree.children = tree.children.filter((n) => !["yaml", "mdxjsEsm"].includes(n.type));
|
|
15
|
+
result = {
|
|
16
|
+
tree,
|
|
17
|
+
frontmatter: (file.data.frontMatter ??
|
|
18
|
+
file.data.frontmatter ??
|
|
19
|
+
{}),
|
|
20
|
+
diagnostics: [],
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
remark,
|
|
25
|
+
rehype,
|
|
26
|
+
read() {
|
|
27
|
+
if (!result)
|
|
28
|
+
throw new Error("cudoc: host compilation did not reach the capture stage");
|
|
29
|
+
return result;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAG9D,qFAAqF;AACrF,MAAM,UAAU,qBAAqB;IACnC,IAAI,OAAyB,CAAA;IAC7B,IAAI,MAAoC,CAAA;IACxC,MAAM,MAAM,GAAqB,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9C,OAAO,GAAG,IAAI,CAAA;IAChB,CAAC,CAAA;IACD,MAAM,MAAM,GAAW,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC3C,IAAI,CAAC,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;QACxE,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,CAAA;QACrC,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAClC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAC9C,CAAA;QACD,MAAM,GAAG;YACP,IAAI;YACJ,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW;gBACjC,IAAI,CAAC,IAAI,CAAC,WAAW;gBACrB,EAAE,CAA4B;YAChC,WAAW,EAAE,EAAE;SAChB,CAAA;IACH,CAAC,CAAA;IACD,OAAO;QACL,MAAM;QACN,MAAM;QACN,IAAI;YACF,IAAI,CAAC,MAAM;gBACT,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAA;YACH,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default implementations of the elements cudoc emits.
|
|
3
|
+
*
|
|
4
|
+
* MDX destructures every capitalized element from the provided components and
|
|
5
|
+
* throws at render time when one is missing, so every name a configured feature
|
|
6
|
+
* can produce needs an implementation somewhere. These are that somewhere:
|
|
7
|
+
* plain markup with class names to hook styles onto, meant to be restyled or
|
|
8
|
+
* replaced rather than used as they are.
|
|
9
|
+
*
|
|
10
|
+
* Only two, because only two are genuinely new. A table laid out by a
|
|
11
|
+
* `tableColumnLayout` rule is rebuilt as `table`/`td` and friends, which every
|
|
12
|
+
* host already maps, so it needs nothing from here. A rule that names
|
|
13
|
+
* capitalized components instead is naming ones the site already has.
|
|
14
|
+
*
|
|
15
|
+
* They live next to the plugin that emits the elements so that the hosts do not
|
|
16
|
+
* each carry a copy and drift apart, and they are compiled to plain JavaScript
|
|
17
|
+
* rather than shipped as JSX because not every host transpiles inside
|
|
18
|
+
* `node_modules` — Docusaurus, for one, does not.
|
|
19
|
+
*
|
|
20
|
+
* `Anchor` renders only the badge. Its id belongs on the heading, put there by
|
|
21
|
+
* `cudoc-remark/heading-ids`: two elements sharing one id make a deep link
|
|
22
|
+
* ambiguous, and most hosts draw their own heading link. A site that does not
|
|
23
|
+
* promote heading ids has to supply an `Anchor` that renders the id itself.
|
|
24
|
+
*/
|
|
25
|
+
import type { ReactNode } from "react";
|
|
26
|
+
export declare function Badge({ children }: {
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
29
|
+
export declare function Anchor({ badge }: {
|
|
30
|
+
badge?: string;
|
|
31
|
+
}): import("react").JSX.Element | null;
|
|
32
|
+
/** Every element a configured cudoc feature can emit, ready to spread. */
|
|
33
|
+
export declare const cudocComponents: {
|
|
34
|
+
Anchor: typeof Anchor;
|
|
35
|
+
Badge: typeof Badge;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,wBAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,+BAE3D;AAED,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,sCAEnD;AAED,0EAA0E;AAC1E,eAAO,MAAM,eAAe;;;CAG3B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function Badge({ children }) {
|
|
3
|
+
return _jsx("span", { className: "cudoc-badge", children: children });
|
|
4
|
+
}
|
|
5
|
+
export function Anchor({ badge }) {
|
|
6
|
+
return badge ? _jsx(Badge, { children: badge }) : null;
|
|
7
|
+
}
|
|
8
|
+
/** Every element a configured cudoc feature can emit, ready to spread. */
|
|
9
|
+
export const cudocComponents = {
|
|
10
|
+
Anchor,
|
|
11
|
+
Badge,
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.tsx"],"names":[],"mappings":";AA2BA,MAAM,UAAU,KAAK,CAAC,EAAE,QAAQ,EAA4B;IAC1D,OAAO,eAAM,SAAS,EAAC,aAAa,YAAE,QAAQ,GAAQ,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,EAAE,KAAK,EAAsB;IAClD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAC,KAAK,cAAE,KAAK,GAAS,CAAC,CAAC,CAAC,IAAI,CAAA;AAC9C,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM;IACN,KAAK;CACN,CAAA"}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from "mdast";
|
|
2
|
+
import type { Plugin } from "unified";
|
|
3
|
+
/** Render persisted embeds inside the current host compilation. */
|
|
4
|
+
declare const embed: Plugin<[{
|
|
5
|
+
outDir?: string;
|
|
6
|
+
sourceRoot?: string;
|
|
7
|
+
}?], Root>;
|
|
8
|
+
export default embed;
|
|
9
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AASrC,mEAAmE;AACnE,QAAA,MAAM,KAAK,EAAE,MAAM,CAAC,CAAC;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,EAAE,IAAI,CA6ElE,CAAA;AACH,eAAe,KAAK,CAAA"}
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parse } from "acorn";
|
|
3
|
+
import { readPreparedEmbeds, embedKey, } from "@cudoment/cudoc/node/prepare-embeds";
|
|
4
|
+
/** Render persisted embeds inside the current host compilation. */
|
|
5
|
+
const embed = (options = {}) => (tree, file) => {
|
|
6
|
+
let prepared;
|
|
7
|
+
let index = 0;
|
|
8
|
+
let usesEmbeds = false;
|
|
9
|
+
// One import per document makes the generated data a real bundler dependency.
|
|
10
|
+
// Rebuilding sources updates embeds.json even when the Markdown page is cached.
|
|
11
|
+
let relativeData = path
|
|
12
|
+
.relative(path.dirname(file.path), path.resolve(options.outDir ?? ".cudoc/documents", "embeds.json"))
|
|
13
|
+
.split(path.sep)
|
|
14
|
+
.join("/");
|
|
15
|
+
if (!relativeData.startsWith("."))
|
|
16
|
+
relativeData = `./${relativeData}`;
|
|
17
|
+
const documentId = path
|
|
18
|
+
.relative(path.resolve(options.sourceRoot ?? "docs"), file.path)
|
|
19
|
+
.split(path.sep)
|
|
20
|
+
.join("/")
|
|
21
|
+
.replace(/\.mdx?$/i, "");
|
|
22
|
+
const expand = (node) => {
|
|
23
|
+
if (!node.children)
|
|
24
|
+
return;
|
|
25
|
+
node.children = node.children.flatMap((child) => {
|
|
26
|
+
if (child.type === "code" && child.lang === "cudoc-embed") {
|
|
27
|
+
prepared ??= readPreparedEmbeds(options.outDir ?? ".cudoc/documents", documentId, String(file.value));
|
|
28
|
+
const result = prepared.blocks[embedKey(documentId, child.value, ++index)];
|
|
29
|
+
if (!result)
|
|
30
|
+
throw new Error(`cudoc: prepared embed missing in ${documentId}; recollect documents`);
|
|
31
|
+
usesEmbeds = true;
|
|
32
|
+
const expression = `_cudocData.blocks[${JSON.stringify(embedKey(documentId, child.value, index))}]`;
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
type: "mdxJsxFlowElement",
|
|
36
|
+
name: "_CudocEmbed",
|
|
37
|
+
attributes: [
|
|
38
|
+
{
|
|
39
|
+
type: "mdxJsxAttribute",
|
|
40
|
+
name: "tree",
|
|
41
|
+
value: {
|
|
42
|
+
type: "mdxJsxAttributeValueExpression",
|
|
43
|
+
value: expression,
|
|
44
|
+
data: {
|
|
45
|
+
estree: parse(expression, {
|
|
46
|
+
ecmaVersion: "latest",
|
|
47
|
+
sourceType: "module",
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
children: [],
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
expand(child);
|
|
58
|
+
return [child];
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
expand(tree);
|
|
62
|
+
if (usesEmbeds) {
|
|
63
|
+
const value = `import { EmbeddedDocument as _CudocEmbed } from "cudoc-remark/runtime";\nimport _cudocData from ${JSON.stringify(relativeData)};`;
|
|
64
|
+
tree.children.unshift({
|
|
65
|
+
type: "mdxjsEsm",
|
|
66
|
+
value,
|
|
67
|
+
data: {
|
|
68
|
+
estree: parse(value, { ecmaVersion: "latest", sourceType: "module" }),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export default embed;
|
|
74
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,EACL,kBAAkB,EAClB,QAAQ,GAET,MAAM,qCAAqC,CAAA;AAE5C,mEAAmE;AACnE,MAAM,KAAK,GACT,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,CACjB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IACb,IAAI,QAAoC,CAAA;IACxC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,8EAA8E;IAC9E,gFAAgF;IAChF,IAAI,YAAY,GAAG,IAAI;SACpB,QAAQ,CACP,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EACvB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,kBAAkB,EAAE,aAAa,CAAC,CAClE;SACA,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;SACf,IAAI,CAAC,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AAI,EAAE,aAAa;wBACnB,UAAU,EAAE;4BACV;gCACE,IAAI,EAAE,iBAAiB;gCACvB,IAAI,EAAE,MAAM;gCACZ,KAAK,EAAE;oCACL,IAAI,EAAE,gCAAgC;oCACtC,KAAK,EAAE,UAAU;oCACjB,IAAI,EAAE;wCACJ,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE;4CACxB,WAAW,EAAE,QAAQ;4CACrB,UAAU,EAAE,QAAQ;yCACrB,CAAC;qCACH;iCACF;6BACF;yBACF;wBACD,QAAQ,EAAE,EAAE;qBACb;iBACF,CAAA;YACH,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,CAAA;YACb,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,MAAM,CAAC,IAA+B,CAAC,CAAA;IACvC,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,KAAK,GAAG,mGAAmG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAA;QAChJ,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;YACpB,IAAI,EAAE,UAAU;YAChB,KAAK;YACL,IAAI,EAAE;gBACJ,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;aACtE;SACqC,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC,CAAA;AACH,eAAe,KAAK,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies the id from a cudoc anchor onto the heading itself.
|
|
3
|
+
*
|
|
4
|
+
* A host that generates its own heading ids slugifies the heading text.
|
|
5
|
+
* Left alone that produces a second id beside cudoc's anchor, and a deep link
|
|
6
|
+
* resolves to whichever the browser finds first. Both Docusaurus and Nextra
|
|
7
|
+
* honour an id already sitting
|
|
8
|
+
* on `data.hProperties` — the property mdast-to-hast turns into the rendered
|
|
9
|
+
* attribute — so writing the anchor id there makes the heading and the anchor
|
|
10
|
+
* agree on one value.
|
|
11
|
+
*
|
|
12
|
+
* This runs as its own plugin rather than inside the single walk, because it
|
|
13
|
+
* has to sit between cudoc and the host's heading plugin, and the host decides
|
|
14
|
+
* where that is.
|
|
15
|
+
*/
|
|
16
|
+
import type { Root } from "mdast";
|
|
17
|
+
import type { Plugin } from "unified";
|
|
18
|
+
export type PromoteAnchorIdsOptions = {
|
|
19
|
+
/** Element name the id is read from. Matches `headingMetadata.anchor.name`. */
|
|
20
|
+
anchorName?: string;
|
|
21
|
+
/** Attribute the id is read from. Matches `headingMetadata.anchor.idAttribute`. */
|
|
22
|
+
idAttribute?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare const promoteAnchorIds: Plugin<[PromoteAnchorIdsOptions?], Root>;
|
|
25
|
+
export default promoteAnchorIds;
|
|
26
|
+
//# sourceMappingURL=heading-ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading-ids.d.ts","sourceRoot":"","sources":["../src/heading-ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAQrC,MAAM,MAAM,uBAAuB,GAAG;IACpC,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAOD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,IAAI,CAoBrE,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies the id from a cudoc anchor onto the heading itself.
|
|
3
|
+
*
|
|
4
|
+
* A host that generates its own heading ids slugifies the heading text.
|
|
5
|
+
* Left alone that produces a second id beside cudoc's anchor, and a deep link
|
|
6
|
+
* resolves to whichever the browser finds first. Both Docusaurus and Nextra
|
|
7
|
+
* honour an id already sitting
|
|
8
|
+
* on `data.hProperties` — the property mdast-to-hast turns into the rendered
|
|
9
|
+
* attribute — so writing the anchor id there makes the heading and the anchor
|
|
10
|
+
* agree on one value.
|
|
11
|
+
*
|
|
12
|
+
* This runs as its own plugin rather than inside the single walk, because it
|
|
13
|
+
* has to sit between cudoc and the host's heading plugin, and the host decides
|
|
14
|
+
* where that is.
|
|
15
|
+
*/
|
|
16
|
+
import { visit } from "unist-util-visit";
|
|
17
|
+
import { extractAnchorId, findAnchorNode, DEFAULT_ANCHOR_NAME, } from "@cudoment/cudoc";
|
|
18
|
+
export const promoteAnchorIds = (options = {}) => {
|
|
19
|
+
const anchorName = options.anchorName ?? DEFAULT_ANCHOR_NAME;
|
|
20
|
+
const idAttribute = options.idAttribute ?? "id";
|
|
21
|
+
return (tree) => {
|
|
22
|
+
visit(tree, "heading", (heading) => {
|
|
23
|
+
const id = extractAnchorId(findAnchorNode(heading.children, anchorName), idAttribute);
|
|
24
|
+
if (!id)
|
|
25
|
+
return;
|
|
26
|
+
const data = (heading.data ?? (heading.data = {}));
|
|
27
|
+
const properties = data.hProperties ?? (data.hProperties = {});
|
|
28
|
+
// An id the author put there another way wins: this only fills a gap.
|
|
29
|
+
if (properties.id === undefined)
|
|
30
|
+
properties.id = id;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export default promoteAnchorIds;
|
|
35
|
+
//# sourceMappingURL=heading-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading-ids.js","sourceRoot":"","sources":["../src/heading-ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAcxB,MAAM,CAAC,MAAM,gBAAgB,GAA6C,CACxE,OAAO,GAAG,EAAE,EACZ,EAAE;IACF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAA;IAC5D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAA;IAE/C,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,OAAgB,EAAE,EAAE;YAC1C,MAAM,EAAE,GAAG,eAAe,CACxB,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,EAC5C,WAAW,CACZ,CAAA;YACD,IAAI,CAAC,EAAE;gBAAE,OAAM;YAEf,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAgB,CAAA;YACjE,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,CAAA;YAC9D,sEAAsE;YACtE,IAAI,UAAU,CAAC,EAAE,KAAK,SAAS;gBAAE,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin list a host adapter hands to its site generator.
|
|
3
|
+
*
|
|
4
|
+
* Docusaurus and Nextra share the transforms and heading id promotion.
|
|
5
|
+
* Default output uses native elements without a cudoc component provider.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluggableList } from "unified";
|
|
8
|
+
import { type CudocRemarkOptions } from "./options.js";
|
|
9
|
+
export type HostPluginOptions = Omit<CudocRemarkOptions, "toc"> & {
|
|
10
|
+
/**
|
|
11
|
+
* Copy each anchor id onto its heading so the host uses it instead of
|
|
12
|
+
* slugifying the heading text. On by default; turning it off leaves the
|
|
13
|
+
* host's ids and cudoc's anchors to disagree.
|
|
14
|
+
*/
|
|
15
|
+
promoteHeadingIds?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const createHostPlugins: (options: HostPluginOptions | undefined, adapter: string) => PluggableList;
|
|
18
|
+
//# sourceMappingURL=host-plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-plugins.d.ts","sourceRoot":"","sources":["../src/host-plugins.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAItE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,GAAG;IAChE;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AA6BD,eAAO,MAAM,iBAAiB,GAC5B,SAAS,iBAAiB,YAAK,EAC/B,SAAS,MAAM,KACd,aAkCF,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin list a host adapter hands to its site generator.
|
|
3
|
+
*
|
|
4
|
+
* Docusaurus and Nextra share the transforms and heading id promotion.
|
|
5
|
+
* Default output uses native elements without a cudoc component provider.
|
|
6
|
+
*/
|
|
7
|
+
import cudocPrepare from "./prepare.js";
|
|
8
|
+
import { resolveOptions } from "./options.js";
|
|
9
|
+
import { promoteAnchorIds } from "./heading-ids.js";
|
|
10
|
+
const KNOWN_KEYS = new Set([
|
|
11
|
+
"syntax",
|
|
12
|
+
"host",
|
|
13
|
+
"format",
|
|
14
|
+
"calloutTypes",
|
|
15
|
+
"components",
|
|
16
|
+
"headingIds",
|
|
17
|
+
"tableCellList",
|
|
18
|
+
"headingMetadata",
|
|
19
|
+
"badge",
|
|
20
|
+
"tableColumnLayout",
|
|
21
|
+
"transforms",
|
|
22
|
+
"promoteHeadingIds",
|
|
23
|
+
]);
|
|
24
|
+
/** Reads the anchor naming back out of the options the transforms were given. */
|
|
25
|
+
const readAnchorNaming = (options) => {
|
|
26
|
+
const headingMetadata = options.headingMetadata;
|
|
27
|
+
if (!headingMetadata || headingMetadata === true)
|
|
28
|
+
return {};
|
|
29
|
+
return {
|
|
30
|
+
anchorName: headingMetadata.anchor?.name,
|
|
31
|
+
idAttribute: headingMetadata.anchor?.idAttribute,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export const createHostPlugins = (options = {}, adapter) => {
|
|
35
|
+
if (typeof options !== "object" || options === null) {
|
|
36
|
+
throw new TypeError(`${adapter}: options must be an object`);
|
|
37
|
+
}
|
|
38
|
+
for (const key of Object.keys(options)) {
|
|
39
|
+
if (!KNOWN_KEYS.has(key)) {
|
|
40
|
+
throw new TypeError(`${adapter}: unknown option "${key}"`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const { promoteHeadingIds = true, ...remarkOptions } = options;
|
|
44
|
+
const host = adapter.includes("docusaurus")
|
|
45
|
+
? "docusaurus"
|
|
46
|
+
: "nextra";
|
|
47
|
+
const resolvedOptions = {
|
|
48
|
+
...remarkOptions,
|
|
49
|
+
host,
|
|
50
|
+
headingIds: "host",
|
|
51
|
+
toc: false,
|
|
52
|
+
};
|
|
53
|
+
// Resolved here rather than at the first document: a rejected key is a
|
|
54
|
+
// configuration mistake, and an error raised while the config loads is far
|
|
55
|
+
// easier to place than the same error raised from inside a loader.
|
|
56
|
+
resolveOptions(resolvedOptions);
|
|
57
|
+
const plugins = [[cudocPrepare, resolvedOptions]];
|
|
58
|
+
// After the transforms, which are what create the anchors it reads.
|
|
59
|
+
if (promoteHeadingIds) {
|
|
60
|
+
plugins.push([promoteAnchorIds, readAnchorNaming(remarkOptions)]);
|
|
61
|
+
}
|
|
62
|
+
return plugins;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingUR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AG,GAAG,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAED,MAAM,EAAE,iBAAiB,GAAG,IAAI,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAA;IAC9D,MAAM,IAAI,GAA4B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;QAClE,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,QAAQ,CAAA;IACZ,MAAM,eAAe,GAAG;QACtB,GAAG,aAAa;QAChB,IAAI;QACJ,UAAU,EAAE,MAAe;QAC3B,GAAG,EAAE,KAAK;KACF,CAAA;IAEV,uEAAuE;IACvE,2EAA2E;IAC3E,mEAAmE;IACnE,cAAc,CAAC,eAAe,CAAC,CAAA;IAE/B,MAAM,OAAO,GAAkB,CAAC,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA;IAEhE,oEAAoE;IACpE,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default, default as cudocPrepare, buildTransforms, getFileSource, } from "./prepare.js";
|
|
2
|
+
export { resolveOptions } from "./options.js";
|
|
3
|
+
export type { CudocRemarkOptions, CudocState, FeatureOption, ResolvedCudocRemarkOptions, } from "./options.js";
|
|
4
|
+
export { addTocExport, collectHeadingToc, createToc, resolveTocOptions, DEFAULT_TOC_EXPORT_NAME, } from "./toc.js";
|
|
5
|
+
export type { Toc, TocEntry, TocHeading, TocOptions } from "./toc.js";
|
|
6
|
+
export { createBadgeTransform, resolveBadgeOptions, DEFAULT_BADGE_NAME, } from "./transforms/badge.js";
|
|
7
|
+
export type { BadgeOptions } from "./transforms/badge.js";
|
|
8
|
+
export { transformTableCellList } from "./transforms/table-cell-list/index.js";
|
|
9
|
+
export { createTableColumnLayoutTransform, resolveTableColumnLayoutOptions, } from "./transforms/table-column-layout/index.js";
|
|
10
|
+
export type { TableColumnLayoutOptions } from "./transforms/table-column-layout/index.js";
|
|
11
|
+
export { promoteAnchorIds } from "./heading-ids.js";
|
|
12
|
+
export type { PromoteAnchorIdsOptions } from "./heading-ids.js";
|
|
13
|
+
export { createHostPlugins } from "./host-plugins.js";
|
|
14
|
+
export type { HostPluginOptions } from "./host-plugins.js";
|
|
15
|
+
export { createCompilerCapture } from "./capture.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,OAAO,IAAI,YAAY,EACvB,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,0BAA0B,GAC3B,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAC9E,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,2CAA2C,CAAA;AAClD,YAAY,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default, default as cudocPrepare, buildTransforms, getFileSource, } from "./prepare.js";
|
|
2
|
+
export { resolveOptions } from "./options.js";
|
|
3
|
+
export { addTocExport, collectHeadingToc, createToc, resolveTocOptions, DEFAULT_TOC_EXPORT_NAME, } from "./toc.js";
|
|
4
|
+
export { createBadgeTransform, resolveBadgeOptions, DEFAULT_BADGE_NAME, } from "./transforms/badge.js";
|
|
5
|
+
export { transformTableCellList } from "./transforms/table-cell-list/index.js";
|
|
6
|
+
export { createTableColumnLayoutTransform, resolveTableColumnLayoutOptions, } from "./transforms/table-column-layout/index.js";
|
|
7
|
+
export { promoteAnchorIds } from "./heading-ids.js";
|
|
8
|
+
export { createHostPlugins } from "./host-plugins.js";
|
|
9
|
+
export { createCompilerCapture } from "./capture.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,OAAO,IAAI,YAAY,EACvB,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAO7C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAC9E,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,2CAA2C,CAAA;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Option resolution.
|
|
3
|
+
*
|
|
4
|
+
* Every option here is JSON-serializable. A bundler may hand a plugin config to
|
|
5
|
+
* a worker, which rules out functions and `RegExp` objects, so syntax is
|
|
6
|
+
* described with delimiter pairs and conditions with declarative selectors.
|
|
7
|
+
* Behaviour that genuinely needs code goes in a custom transform instead.
|
|
8
|
+
*
|
|
9
|
+
* Unknown keys are rejected rather than ignored: a typo in a config that is
|
|
10
|
+
* silently dropped shows up much later as missing output.
|
|
11
|
+
*/
|
|
12
|
+
import { type HeadingMetadataOptions, type ResolvedHeadingMetadataOptions, type Transform, type TransformState } from "@cudoment/cudoc";
|
|
13
|
+
import { type BadgeOptions, type ResolvedBadgeOptions } from "./transforms/badge.js";
|
|
14
|
+
import { type ResolvedTableColumnLayoutOptions, type TableColumnLayoutOptions } from "./transforms/table-column-layout/index.js";
|
|
15
|
+
import { type ResolvedTocOptions, type TocOptions } from "./toc.js";
|
|
16
|
+
import type { Toc } from "./toc.js";
|
|
17
|
+
import { type DocumentOptions } from "@cudoment/cudoc/document";
|
|
18
|
+
export type CudocState = TransformState & {
|
|
19
|
+
toc: Toc;
|
|
20
|
+
};
|
|
21
|
+
/** A feature is off when `false`, on with defaults when `true` or omitted. */
|
|
22
|
+
export type FeatureOption<Options> = boolean | Options | undefined;
|
|
23
|
+
export type CudocRemarkOptions = Pick<DocumentOptions, "syntax" | "host" | "format" | "calloutTypes" | "components" | "headingIds"> & {
|
|
24
|
+
/** List syntax inside table cells. */
|
|
25
|
+
tableCellList?: boolean;
|
|
26
|
+
/** Anchor id and badge written in a heading. */
|
|
27
|
+
headingMetadata?: FeatureOption<HeadingMetadataOptions>;
|
|
28
|
+
/** Badge syntax in ordinary prose. */
|
|
29
|
+
badge?: FeatureOption<BadgeOptions>;
|
|
30
|
+
/** Table of contents collection and export. Off unless configured. */
|
|
31
|
+
toc?: FeatureOption<TocOptions>;
|
|
32
|
+
/** Column layout rules, applied in order. Empty by default. */
|
|
33
|
+
tableColumnLayout?: TableColumnLayoutOptions[];
|
|
34
|
+
/** Extra transforms, run alongside the built-in ones. */
|
|
35
|
+
transforms?: {
|
|
36
|
+
pre?: Transform<CudocState>[];
|
|
37
|
+
post?: Transform<CudocState>[];
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export type ResolvedCudocRemarkOptions = {
|
|
41
|
+
tableCellList: boolean;
|
|
42
|
+
headingMetadata: ResolvedHeadingMetadataOptions | null;
|
|
43
|
+
badge: ResolvedBadgeOptions | null;
|
|
44
|
+
toc: ResolvedTocOptions | null;
|
|
45
|
+
tableColumnLayout: ResolvedTableColumnLayoutOptions[];
|
|
46
|
+
transforms: {
|
|
47
|
+
pre: Transform<CudocState>[];
|
|
48
|
+
post: Transform<CudocState>[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export declare const resolveOptions: (options?: CudocRemarkOptions) => ResolvedCudocRemarkOptions;
|
|
52
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,8BAA8B,EACnC,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAEL,KAAK,gCAAgC,EAC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G,IAAI,CAAA;IAC9B,iBAAiB,EAAE,gCAAgC,EAAE,CAAA;IACrD,UAAU,EAAE;QACV,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,CAAA;QAC5B,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,CAAA;KAC9B,CAAA;CACF,CAAA;AA2CD,eAAO,MAAM,cAAc,GACzB,UAAS,kBAAuB,KAC/B,0BA+CF,CAAA"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Option resolution.
|
|
3
|
+
*
|
|
4
|
+
* Every option here is JSON-serializable. A bundler may hand a plugin config to
|
|
5
|
+
* a worker, which rules out functions and `RegExp` objects, so syntax is
|
|
6
|
+
* described with delimiter pairs and conditions with declarative selectors.
|
|
7
|
+
* Behaviour that genuinely needs code goes in a custom transform instead.
|
|
8
|
+
*
|
|
9
|
+
* Unknown keys are rejected rather than ignored: a typo in a config that is
|
|
10
|
+
* silently dropped shows up much later as missing output.
|
|
11
|
+
*/
|
|
12
|
+
import { resolveHeadingMetadataOptions, } from "@cudoment/cudoc";
|
|
13
|
+
import { resolveBadgeOptions, } from "./transforms/badge.js";
|
|
14
|
+
import { resolveTableColumnLayoutOptions, } from "./transforms/table-column-layout/index.js";
|
|
15
|
+
import { resolveTocOptions, } from "./toc.js";
|
|
16
|
+
import { resolveSyntax } from "@cudoment/cudoc/document";
|
|
17
|
+
const KNOWN_KEYS = new Set([
|
|
18
|
+
"syntax",
|
|
19
|
+
"host",
|
|
20
|
+
"format",
|
|
21
|
+
"calloutTypes",
|
|
22
|
+
"components",
|
|
23
|
+
"headingIds",
|
|
24
|
+
"tableCellList",
|
|
25
|
+
"headingMetadata",
|
|
26
|
+
"badge",
|
|
27
|
+
"toc",
|
|
28
|
+
"tableColumnLayout",
|
|
29
|
+
"transforms",
|
|
30
|
+
]);
|
|
31
|
+
const assertKnownKeys = (options) => {
|
|
32
|
+
const unknown = Object.keys(options).filter((key) => !KNOWN_KEYS.has(key));
|
|
33
|
+
if (unknown.length > 0) {
|
|
34
|
+
throw new TypeError(`cudoc: unknown option${unknown.length > 1 ? "s" : ""} ${unknown
|
|
35
|
+
.map((key) => `"${key}"`)
|
|
36
|
+
.join(", ")}. Known options: ${[...KNOWN_KEYS].join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Resolves a feature that is on by default.
|
|
41
|
+
*
|
|
42
|
+
* `false` disables it, `true` or an absent value takes the defaults, and an
|
|
43
|
+
* object is the caller's configuration.
|
|
44
|
+
*/
|
|
45
|
+
const resolveFeature = (value, resolve) => {
|
|
46
|
+
if (value === false)
|
|
47
|
+
return null;
|
|
48
|
+
if (value === true || value === undefined)
|
|
49
|
+
return resolve();
|
|
50
|
+
return resolve(value);
|
|
51
|
+
};
|
|
52
|
+
export const resolveOptions = (options = {}) => {
|
|
53
|
+
if (typeof options !== "object" || options === null) {
|
|
54
|
+
throw new TypeError("cudoc: options must be an object");
|
|
55
|
+
}
|
|
56
|
+
assertKnownKeys(options);
|
|
57
|
+
if (options.syntax !== undefined) {
|
|
58
|
+
resolveSyntax(options.syntax);
|
|
59
|
+
for (const [feature, legacy] of [
|
|
60
|
+
["headingAnchor", "headingMetadata"],
|
|
61
|
+
["badge", "badge"],
|
|
62
|
+
["tableCellList", "tableCellList"],
|
|
63
|
+
]) {
|
|
64
|
+
if (options[legacy] !== undefined)
|
|
65
|
+
throw new TypeError(`cudoc: configure ${feature} through syntax or ${legacy}, not both`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (options.tableColumnLayout !== undefined &&
|
|
69
|
+
!Array.isArray(options.tableColumnLayout)) {
|
|
70
|
+
throw new TypeError("tableColumnLayout must be an array of rules");
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
tableCellList: options.tableCellList !== false,
|
|
74
|
+
headingMetadata: resolveFeature(options.headingMetadata, resolveHeadingMetadataOptions),
|
|
75
|
+
badge: resolveFeature(options.badge, resolveBadgeOptions),
|
|
76
|
+
// A host usually builds its own table of contents, so this one stays off
|
|
77
|
+
// until it is asked for.
|
|
78
|
+
toc: options.toc === undefined || options.toc === false
|
|
79
|
+
? null
|
|
80
|
+
: resolveFeature(options.toc, resolveTocOptions),
|
|
81
|
+
tableColumnLayout: (options.tableColumnLayout ?? []).map((rule, index) => resolveTableColumnLayoutOptions(rule, `tableColumnLayout[${index}]`)),
|
|
82
|
+
transforms: {
|
|
83
|
+
pre: options.transforms?.pre ?? [],
|
|
84
|
+
post: options.transforms?.post ?? [],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,6BAA6B,GAK9B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,mBAAmB,GAGpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,+BAA+B,GAGhC,MAAM,2CAA2C,CAAA;AAClD,OAAO,EACL,iBAAiB,GAGlB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,aAAa,EAAwB,MAAM,0BAA0B,CAAA;AA0C9E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,iBAAiB;IACjB,OAAO;IACP,KAAK;IACL,mBAAmB;IACnB,YAAY;CACb,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,EAAE;IAC1C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CA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