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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -0
  3. package/dist/capture.d.ts +10 -0
  4. package/dist/capture.d.ts.map +1 -0
  5. package/dist/capture.js +33 -0
  6. package/dist/capture.js.map +1 -0
  7. package/dist/components/index.d.ts +37 -0
  8. package/dist/components/index.d.ts.map +1 -0
  9. package/dist/components/index.js +13 -0
  10. package/dist/components/index.js.map +1 -0
  11. package/dist/embed.d.ts +9 -0
  12. package/dist/embed.d.ts.map +1 -0
  13. package/dist/embed.js +74 -0
  14. package/dist/embed.js.map +1 -0
  15. package/dist/heading-ids.d.ts +26 -0
  16. package/dist/heading-ids.d.ts.map +1 -0
  17. package/dist/heading-ids.js +35 -0
  18. package/dist/heading-ids.js.map +1 -0
  19. package/dist/host-plugins.d.ts +18 -0
  20. package/dist/host-plugins.d.ts.map +1 -0
  21. package/dist/host-plugins.js +64 -0
  22. package/dist/host-plugins.js.map +1 -0
  23. package/dist/index.d.ts +16 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +10 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/options.d.ts +52 -0
  28. package/dist/options.d.ts.map +1 -0
  29. package/dist/options.js +88 -0
  30. package/dist/options.js.map +1 -0
  31. package/dist/prepare.d.ts +25 -0
  32. package/dist/prepare.d.ts.map +1 -0
  33. package/dist/prepare.js +115 -0
  34. package/dist/prepare.js.map +1 -0
  35. package/dist/runtime.d.ts +11 -0
  36. package/dist/runtime.d.ts.map +1 -0
  37. package/dist/runtime.js +12 -0
  38. package/dist/runtime.js.map +1 -0
  39. package/dist/toc.d.ts +58 -0
  40. package/dist/toc.d.ts.map +1 -0
  41. package/dist/toc.js +126 -0
  42. package/dist/toc.js.map +1 -0
  43. package/dist/transforms/badge.d.ts +28 -0
  44. package/dist/transforms/badge.d.ts.map +1 -0
  45. package/dist/transforms/badge.js +58 -0
  46. package/dist/transforms/badge.js.map +1 -0
  47. package/dist/transforms/table-cell-list/build-table-cell-children.d.ts +2 -0
  48. package/dist/transforms/table-cell-list/build-table-cell-children.d.ts.map +1 -0
  49. package/dist/transforms/table-cell-list/build-table-cell-children.js +3 -0
  50. package/dist/transforms/table-cell-list/build-table-cell-children.js.map +1 -0
  51. package/dist/transforms/table-cell-list/elements.d.ts +2 -0
  52. package/dist/transforms/table-cell-list/elements.d.ts.map +1 -0
  53. package/dist/transforms/table-cell-list/elements.js +3 -0
  54. package/dist/transforms/table-cell-list/elements.js.map +1 -0
  55. package/dist/transforms/table-cell-list/index.d.ts +2 -0
  56. package/dist/transforms/table-cell-list/index.d.ts.map +1 -0
  57. package/dist/transforms/table-cell-list/index.js +3 -0
  58. package/dist/transforms/table-cell-list/index.js.map +1 -0
  59. package/dist/transforms/table-cell-list/nodes.d.ts +2 -0
  60. package/dist/transforms/table-cell-list/nodes.d.ts.map +1 -0
  61. package/dist/transforms/table-cell-list/nodes.js +3 -0
  62. package/dist/transforms/table-cell-list/nodes.js.map +1 -0
  63. package/dist/transforms/table-cell-list/parse-inline-markdown.d.ts +2 -0
  64. package/dist/transforms/table-cell-list/parse-inline-markdown.d.ts.map +1 -0
  65. package/dist/transforms/table-cell-list/parse-inline-markdown.js +3 -0
  66. package/dist/transforms/table-cell-list/parse-inline-markdown.js.map +1 -0
  67. package/dist/transforms/table-cell-list/parse-table-cell-list.d.ts +2 -0
  68. package/dist/transforms/table-cell-list/parse-table-cell-list.d.ts.map +1 -0
  69. package/dist/transforms/table-cell-list/parse-table-cell-list.js +3 -0
  70. package/dist/transforms/table-cell-list/parse-table-cell-list.js.map +1 -0
  71. package/dist/transforms/table-column-layout/create-table.d.ts +2 -0
  72. package/dist/transforms/table-column-layout/create-table.d.ts.map +1 -0
  73. package/dist/transforms/table-column-layout/create-table.js +3 -0
  74. package/dist/transforms/table-column-layout/create-table.js.map +1 -0
  75. package/dist/transforms/table-column-layout/index.d.ts +2 -0
  76. package/dist/transforms/table-column-layout/index.d.ts.map +1 -0
  77. package/dist/transforms/table-column-layout/index.js +3 -0
  78. package/dist/transforms/table-column-layout/index.js.map +1 -0
  79. package/dist/transforms/table-column-layout/split-cell.d.ts +2 -0
  80. package/dist/transforms/table-column-layout/split-cell.d.ts.map +1 -0
  81. package/dist/transforms/table-column-layout/split-cell.js +3 -0
  82. package/dist/transforms/table-column-layout/split-cell.js.map +1 -0
  83. package/package.json +110 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The remark plugin that applies cudoc's syntax and layout transforms.
3
+ *
4
+ * The authoring default uses common document normalization, then optional
5
+ * custom transforms and TOC collection. Explicit component-transform options
6
+ * use buildTransforms: cells run on entry and table layout runs on exit so
7
+ * table-wide transforms see normalized cells.
8
+ */
9
+ import type { Root } from "mdast";
10
+ import type { Plugin } from "unified";
11
+ import type { VFile } from "vfile";
12
+ import { type Transform } from "@cudoment/cudoc";
13
+ import { resolveOptions, type CudocRemarkOptions, type CudocState } from "./options.js";
14
+ /**
15
+ * The source text is needed to read list syntax out of table cells, which mdast
16
+ * does not preserve. Without it that transform leaves cells untouched.
17
+ */
18
+ export declare const getFileSource: (file: VFile) => string | null;
19
+ export declare const buildTransforms: (options: ReturnType<typeof resolveOptions>) => {
20
+ pre: Transform<CudocState>[];
21
+ post: Transform<CudocState>[];
22
+ };
23
+ declare const cudocPrepare: Plugin<[CudocRemarkOptions?], Root>;
24
+ export default cudocPrepare;
25
+ //# sourceMappingURL=prepare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../src/prepare.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,EACL,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,UAAU,EAChB,MAAM,cAAc,CAAA;AASrB;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,KAAK,KAAG,MAAM,GAAG,IAIpD,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,SAAS,UAAU,CAAC,OAAO,cAAc,CAAC,KACzC;IAAE,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,CAAA;CA+B/D,CAAA;AAED,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,EAAE,IAAI,CA0DrD,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The remark plugin that applies cudoc's syntax and layout transforms.
3
+ *
4
+ * The authoring default uses common document normalization, then optional
5
+ * custom transforms and TOC collection. Explicit component-transform options
6
+ * use buildTransforms: cells run on entry and table layout runs on exit so
7
+ * table-wide transforms see normalized cells.
8
+ */
9
+ import { transformHeadingAnchor, walk } from "@cudoment/cudoc";
10
+ import { resolveOptions, } from "./options.js";
11
+ import { createBadgeTransform } from "./transforms/badge.js";
12
+ import { createTableColumnLayoutTransform } from "./transforms/table-column-layout/index.js";
13
+ import { transformTableCellList } from "./transforms/table-cell-list/index.js";
14
+ import { addTocExport, collectHeadingToc, createToc } from "./toc.js";
15
+ import remarkDirective from "remark-directive";
16
+ import remarkFrontmatter from "remark-frontmatter";
17
+ import { normalizeDocument } from "@cudoment/cudoc/document";
18
+ /**
19
+ * The source text is needed to read list syntax out of table cells, which mdast
20
+ * does not preserve. Without it that transform leaves cells untouched.
21
+ */
22
+ export const getFileSource = (file) => {
23
+ if (typeof file.value === "string")
24
+ return file.value;
25
+ if (typeof file.toString === "function")
26
+ return file.toString();
27
+ return null;
28
+ };
29
+ export const buildTransforms = (options) => {
30
+ const pre = [];
31
+ // Cells first: later transforms read cell contents and must not see raw
32
+ // markers.
33
+ if (options.tableCellList)
34
+ pre.push(transformTableCellList);
35
+ if (options.headingMetadata || options.toc) {
36
+ const headingMetadata = options.headingMetadata;
37
+ const toc = options.toc;
38
+ pre.push(({ node, state }) => {
39
+ if (node.type !== "heading")
40
+ return;
41
+ const heading = node;
42
+ // Anchors are created before the table of contents is collected, because
43
+ // an entry is keyed by the anchor id.
44
+ if (headingMetadata)
45
+ transformHeadingAnchor(heading, headingMetadata);
46
+ if (toc)
47
+ collectHeadingToc(state.toc, heading, toc);
48
+ });
49
+ }
50
+ // Badges in prose run after headings, so heading badges are already gone.
51
+ if (options.badge)
52
+ pre.push(createBadgeTransform(options.badge));
53
+ pre.push(...options.transforms.pre);
54
+ const post = options.tableColumnLayout.map((rule) => createTableColumnLayoutTransform(rule));
55
+ post.push(...options.transforms.post);
56
+ return { pre, post };
57
+ };
58
+ const cudocPrepare = function (options = {}) {
59
+ const resolved = resolveOptions(options);
60
+ // Component transforms are an explicit low-level API, never the authoring default.
61
+ const portable = options.syntax !== undefined ||
62
+ (options.headingMetadata === undefined &&
63
+ options.badge === undefined &&
64
+ options.tableCellList === undefined);
65
+ this.use(remarkFrontmatter);
66
+ if (portable && options.host === "docusaurus")
67
+ this.use(remarkDirective);
68
+ const { pre, post } = buildTransforms(resolved);
69
+ return function (tree, file) {
70
+ const format = options.format ?? (file.extname === ".md" ? "md" : "mdx");
71
+ if (portable || format === "md") {
72
+ tree.children = tree.children.filter((node) => node.type !== "yaml");
73
+ const diagnostics = normalizeDocument(tree, getFileSource(file) ?? "", {
74
+ ...options,
75
+ format,
76
+ });
77
+ for (const diagnostic of diagnostics)
78
+ file.message(diagnostic.message, {
79
+ place: diagnostic.position,
80
+ ruleId: diagnostic.code,
81
+ source: "cudoc",
82
+ });
83
+ if (resolved.transforms.pre.length || resolved.transforms.post.length)
84
+ walk({
85
+ tree,
86
+ state: { source: getFileSource(file), toc: createToc() },
87
+ preTransforms: resolved.transforms.pre,
88
+ postTransforms: resolved.transforms.post,
89
+ });
90
+ if (resolved.toc) {
91
+ const toc = createToc();
92
+ for (const heading of tree.children)
93
+ if (heading.type === "heading")
94
+ collectHeadingToc(toc, heading, resolved.toc);
95
+ if (format !== "md")
96
+ addTocExport(tree, toc, resolved.toc);
97
+ }
98
+ return;
99
+ }
100
+ const state = {
101
+ source: getFileSource(file),
102
+ toc: createToc(),
103
+ };
104
+ walk({
105
+ postTransforms: post,
106
+ preTransforms: pre,
107
+ state,
108
+ tree,
109
+ });
110
+ if (resolved.toc)
111
+ addTocExport(tree, state.toc, resolved.toc);
112
+ };
113
+ };
114
+ export default cudocPrepare;
115
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../src/prepare.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAkB,MAAM,iBAAiB,CAAA;AAC9E,OAAO,EACL,cAAc,GAGf,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAA;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,eAAe,MAAM,kBAAkB,CAAA;AAC9C,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAW,EAAiB,EAAE;IAC1D,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,KAAK,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,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC/D,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { Root } from "mdast";
2
+ /** Automatically imported by the embed plugin; authors never register this component. */
3
+ export declare function EmbeddedDocument({ tree }: {
4
+ tree: Root;
5
+ }): import("react").DetailedReactHTMLElement<{
6
+ className: string;
7
+ dangerouslySetInnerHTML: {
8
+ __html: string;
9
+ };
10
+ }, HTMLElement>;
11
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAGjC,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE;;;;;gBAOxD"}
@@ -0,0 +1,12 @@
1
+ import { createElement } from "react";
2
+ import { renderDocument } from "@cudoment/cudoc/render";
3
+ /** Automatically imported by the embed plugin; authors never register this component. */
4
+ export function EmbeddedDocument({ tree }) {
5
+ if (!tree)
6
+ throw new Error("cudoc: prepared embed missing; recollect documents");
7
+ return createElement("div", {
8
+ className: "cudoc-embed",
9
+ dangerouslySetInnerHTML: { __html: renderDocument(tree) },
10
+ });
11
+ }
12
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEvD,yFAAyF;AACzF,MAAM,UAAU,gBAAgB,CAAC,EAAE,IAAI,EAAkB;IACvD,IAAI,CAAC,IAAI;QACP,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACvE,OAAO,aAAa,CAAC,KAAK,EAAE;QAC1B,SAAS,EAAE,aAAa;QACxB,uBAAuB,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,IAAI,CAAC,EAAE;KAC1D,CAAC,CAAA;AACJ,CAAC"}
package/dist/toc.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Collects a table of contents while the tree is being walked, and exports it
3
+ * from the compiled module so the page can render it without re-reading the
4
+ * document at runtime.
5
+ *
6
+ * Hosts that build their own table of contents should leave this off.
7
+ */
8
+ import type { Heading, Root } from "mdast";
9
+ import { type DelimiterPair } from "@cudoment/cudoc";
10
+ export type TocEntry = {
11
+ id: string;
12
+ text: string;
13
+ };
14
+ export type TocHeading = TocEntry & {
15
+ children: TocEntry[];
16
+ };
17
+ export type Toc = {
18
+ title: string | null;
19
+ headings: TocHeading[];
20
+ };
21
+ export declare const DEFAULT_TOC_EXPORT_NAME = "toc";
22
+ export type TocOptions = {
23
+ /** Heading depth taken as the document title, or `false` to collect none. */
24
+ titleDepth?: number | false;
25
+ /**
26
+ * Depths collected into the list, outermost first. Two levels are supported:
27
+ * the first becomes a top-level entry and the second its child.
28
+ */
29
+ depths?: number[];
30
+ /** Name of the exported binding. */
31
+ exportName?: string;
32
+ /** Badge syntax stripped from heading text before it is used as a label. */
33
+ badgeDelimiters?: DelimiterPair;
34
+ /** Anchor element and attribute the id is read from. */
35
+ anchor?: {
36
+ name?: string;
37
+ idAttribute?: string;
38
+ };
39
+ };
40
+ export type ResolvedTocOptions = {
41
+ titleDepth: number | false;
42
+ depths: number[];
43
+ exportName: string;
44
+ badgeDelimiters: DelimiterPair;
45
+ anchor: {
46
+ name: string;
47
+ idAttribute: string;
48
+ };
49
+ };
50
+ export declare const resolveTocOptions: (options?: TocOptions) => ResolvedTocOptions;
51
+ export declare const createToc: () => Toc;
52
+ /**
53
+ * A heading without an anchor id is skipped: an entry that cannot be linked to
54
+ * would render as a dead row.
55
+ */
56
+ export declare const collectHeadingToc: (toc: Toc, node: Heading, options: ResolvedTocOptions) => void;
57
+ export declare const addTocExport: (tree: Root, toc: Toc, options: ResolvedTocOptions) => void;
58
+ //# sourceMappingURL=toc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../src/toc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAmB,IAAI,EAAe,MAAM,OAAO,CAAA;AAExE,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAA;AAExB,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG;IAClC,QAAQ,EAAE,QAAQ,EAAE,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,GAAG,GAAG;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,QAAQ,EAAE,UAAU,EAAE,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,uBAAuB,QAAQ,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG;IACvB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAC3B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,aAAa,CAAA;IAC/B,wDAAwD;IACxD,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACjD,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,GAAG,KAAK,CAAA;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,aAAa,CAAA;IAC9B,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,UAAS,UAAe,KACvB,kBA+BF,CAAA;AAED,eAAO,MAAM,SAAS,QAAO,GAG3B,CAAA;AAgDF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,GAAG,EACR,MAAM,OAAO,EACb,SAAS,kBAAkB,KAC1B,IA6BF,CAAA;AAiCD,eAAO,MAAM,YAAY,GACvB,MAAM,IAAI,EACV,KAAK,GAAG,EACR,SAAS,kBAAkB,KAC1B,IAEF,CAAA"}
package/dist/toc.js ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Collects a table of contents while the tree is being walked, and exports it
3
+ * from the compiled module so the page can render it without re-reading the
4
+ * document at runtime.
5
+ *
6
+ * Hosts that build their own table of contents should leave this off.
7
+ */
8
+ import { valueToEstree } from "estree-util-value-to-estree";
9
+ import { extractAnchorId, findAnchorNode, splitByDelimiters, DEFAULT_ANCHOR_NAME, DEFAULT_BADGE_DELIMITERS, } from "@cudoment/cudoc";
10
+ export const DEFAULT_TOC_EXPORT_NAME = "toc";
11
+ export const resolveTocOptions = (options = {}) => {
12
+ const depths = options.depths ?? [2, 3];
13
+ if (!Array.isArray(depths) ||
14
+ depths.length === 0 ||
15
+ depths.length > 2 ||
16
+ !depths.every((depth) => Number.isInteger(depth) && depth >= 1 && depth <= 6)) {
17
+ throw new TypeError("toc.depths must be one or two heading depths of 1-6");
18
+ }
19
+ const titleDepth = options.titleDepth ?? 1;
20
+ if (titleDepth !== false &&
21
+ (!Number.isInteger(titleDepth) || titleDepth < 1 || titleDepth > 6)) {
22
+ throw new TypeError("toc.titleDepth must be a depth of 1-6, or false");
23
+ }
24
+ return {
25
+ titleDepth,
26
+ depths: [...depths],
27
+ exportName: options.exportName ?? DEFAULT_TOC_EXPORT_NAME,
28
+ badgeDelimiters: options.badgeDelimiters ?? DEFAULT_BADGE_DELIMITERS,
29
+ anchor: {
30
+ name: options.anchor?.name ?? DEFAULT_ANCHOR_NAME,
31
+ idAttribute: options.anchor?.idAttribute ?? "id",
32
+ },
33
+ };
34
+ };
35
+ export const createToc = () => ({
36
+ title: null,
37
+ headings: [],
38
+ });
39
+ const hasPhrasingChildren = (node) => "children" in node && Array.isArray(node.children);
40
+ /**
41
+ * Reads a heading's label.
42
+ *
43
+ * Badge syntax is dropped from ordinary text, but kept inside a link, where the
44
+ * same characters are part of the link's own text rather than cudoc syntax.
45
+ */
46
+ const collectText = (nodes, badgeDelimiters, preserveMetadata = false) => {
47
+ const values = nodes.flatMap((node) => {
48
+ if (["badge", "permalink"].includes(node.data?.cudoc?.kind ?? ""))
49
+ return [];
50
+ if (node.type === "text") {
51
+ return preserveMetadata
52
+ ? [node.value]
53
+ : splitByDelimiters(node.value, badgeDelimiters).map((part) => part.value);
54
+ }
55
+ if ("value" in node)
56
+ return [node.value];
57
+ if (hasPhrasingChildren(node)) {
58
+ const preserveChild = preserveMetadata ||
59
+ node.type === "link" ||
60
+ node.type === "linkReference";
61
+ return [collectText(node.children, badgeDelimiters, preserveChild)];
62
+ }
63
+ return [""];
64
+ });
65
+ return values.join("").replace(/\s+/g, " ").trim();
66
+ };
67
+ /**
68
+ * A heading without an anchor id is skipped: an entry that cannot be linked to
69
+ * would render as a dead row.
70
+ */
71
+ export const collectHeadingToc = (toc, node, options) => {
72
+ const [topDepth, childDepth] = options.depths;
73
+ const isTitle = options.titleDepth !== false && node.depth === options.titleDepth;
74
+ if (!isTitle && node.depth !== topDepth && node.depth !== childDepth)
75
+ return;
76
+ const text = collectText(node.children, options.badgeDelimiters);
77
+ if (!text)
78
+ return;
79
+ if (isTitle) {
80
+ toc.title = text;
81
+ return;
82
+ }
83
+ const id = node.data?.hProperties
84
+ ?.id ??
85
+ extractAnchorId(findAnchorNode(node.children, options.anchor.name), options.anchor.idAttribute);
86
+ if (!id)
87
+ return;
88
+ if (node.depth === topDepth) {
89
+ toc.headings.push({ id, text, children: [] });
90
+ return;
91
+ }
92
+ toc.headings.at(-1)?.children.push({ id, text });
93
+ };
94
+ const createTocExportNode = (toc, exportName) => ({
95
+ type: "mdxjsEsm",
96
+ value: "",
97
+ data: {
98
+ estree: {
99
+ type: "Program",
100
+ sourceType: "module",
101
+ body: [
102
+ {
103
+ type: "ExportNamedDeclaration",
104
+ declaration: {
105
+ type: "VariableDeclaration",
106
+ kind: "const",
107
+ declarations: [
108
+ {
109
+ type: "VariableDeclarator",
110
+ id: { type: "Identifier", name: exportName },
111
+ init: valueToEstree(toc),
112
+ },
113
+ ],
114
+ },
115
+ specifiers: [],
116
+ source: null,
117
+ attributes: [],
118
+ },
119
+ ],
120
+ },
121
+ },
122
+ });
123
+ export const addTocExport = (tree, toc, options) => {
124
+ tree.children.unshift(createTocExportNode(toc, options.exportName));
125
+ };
126
+ //# sourceMappingURL=toc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc.js","sourceRoot":"","sources":["../src/toc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,iBAAiB,CAAA;AAgBxB,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAA;AA0B5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,UAAsB,EAAE,EACJ,EAAE;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACvC,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACtB,MAAM,CAAC,MAAM,KAAK,CAAC;QACnB,MAAM,CAAC,MAAM,GAAG,CAAC;QACjB,CAAC,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,WAAW,EAAE;wBACX,IAAI,EAAE,qBAAqB;wBAC3B,IAAI,EAAE,OAAO;wBACb,YAAY,EAAE;4BACZ;gCACE,IAAI,EAAE,oBAAoB;gCAC1B,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE;gCAC5C,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC;6BACzB;yBACF;qBACF;oBACD,UAAU,EAAE,EAAE;oBACd,MAAM,EAAE,IAAI;oBACZ,UAAU,EAAE,EAAE;iBACf;aACF;SACF;KACF;CACF,CAA2B,CAAA;AAE9B,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAU,EACV,GAAQ,EACR,OAA2B,EACrB,EAAE;IACR,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AACrE,CAAC,CAAA"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Turns badge syntax in ordinary prose into a badge element.
3
+ *
4
+ * Heading badges are handled by the heading-metadata transform, which moves
5
+ * them onto the anchor. This one covers every other text node.
6
+ */
7
+ import type { DelimiterPair, TransformContext } from "@cudoment/cudoc";
8
+ export declare const DEFAULT_BADGE_NAME = "Badge";
9
+ /** Node types whose subtree is left alone. */
10
+ export declare const DEFAULT_EXCLUDED_ANCESTORS: readonly ["link", "linkReference"];
11
+ export type BadgeOptions = {
12
+ /** Element name emitted for a badge. */
13
+ name?: string;
14
+ delimiters?: DelimiterPair;
15
+ /**
16
+ * Badge syntax inside these nodes is left as literal text. A link label is
17
+ * excluded by default: a badge there would nest interactive content.
18
+ */
19
+ excludeAncestors?: string[];
20
+ };
21
+ export type ResolvedBadgeOptions = {
22
+ name: string;
23
+ delimiters: DelimiterPair;
24
+ excludeAncestors: string[];
25
+ };
26
+ export declare const resolveBadgeOptions: (options?: BadgeOptions) => ResolvedBadgeOptions;
27
+ export declare const createBadgeTransform: (options: ResolvedBadgeOptions) => ({ ancestors, index, node, parent }: TransformContext) => void;
28
+ //# sourceMappingURL=badge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../../src/transforms/badge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOtE,eAAO,MAAM,kBAAkB,UAAU,CAAA;AAEzC,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,oCAAqC,CAAA;AAE5E,MAAM,MAAM,YAAY,GAAG;IACzB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,aAAa,CAAA;IACzB,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,UAAS,YAAiB,KACzB,oBAmBF,CAAA;AAcD,eAAO,MAAM,oBAAoB,GAC9B,SAAS,oBAAoB,MAC7B,oCAAoC,gBAAgB,KAAG,IAyBvD,CAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Turns badge syntax in ordinary prose into a badge element.
3
+ *
4
+ * Heading badges are handled by the heading-metadata transform, which moves
5
+ * them onto the anchor. This one covers every other text node.
6
+ */
7
+ import { assertDelimiterPair, DEFAULT_BADGE_DELIMITERS, splitByDelimiters, } from "@cudoment/cudoc";
8
+ export const DEFAULT_BADGE_NAME = "Badge";
9
+ /** Node types whose subtree is left alone. */
10
+ export const DEFAULT_EXCLUDED_ANCESTORS = ["link", "linkReference"];
11
+ export const resolveBadgeOptions = (options = {}) => {
12
+ if (options.excludeAncestors !== undefined) {
13
+ if (!Array.isArray(options.excludeAncestors) ||
14
+ !options.excludeAncestors.every((type) => typeof type === "string")) {
15
+ throw new TypeError("badge.excludeAncestors must be an array of strings");
16
+ }
17
+ }
18
+ return {
19
+ name: options.name ?? DEFAULT_BADGE_NAME,
20
+ delimiters: options.delimiters
21
+ ? assertDelimiterPair(options.delimiters, "badge.delimiters")
22
+ : DEFAULT_BADGE_DELIMITERS,
23
+ excludeAncestors: options.excludeAncestors
24
+ ? [...options.excludeAncestors]
25
+ : [...DEFAULT_EXCLUDED_ANCESTORS],
26
+ };
27
+ };
28
+ const createBadgeNode = (value, name) => ({
29
+ type: "mdxJsxTextElement",
30
+ name,
31
+ attributes: [],
32
+ children: [
33
+ {
34
+ type: "text",
35
+ value,
36
+ },
37
+ ],
38
+ });
39
+ export const createBadgeTransform = (options) => ({ ancestors, index, node, parent }) => {
40
+ if (node.type !== "text" || !parent || typeof index !== "number")
41
+ return;
42
+ if (options.excludeAncestors.includes(parent.type) ||
43
+ ancestors?.some((ancestor) => options.excludeAncestors.includes(ancestor.parent.type))) {
44
+ return;
45
+ }
46
+ const textNode = node;
47
+ const parts = splitByDelimiters(textNode.value, options.delimiters);
48
+ if (!parts.some((part) => part.type === "delimited"))
49
+ return;
50
+ const newNodes = parts.map((part) => part.type === "delimited"
51
+ ? createBadgeNode(part.value, options.name)
52
+ : {
53
+ type: "text",
54
+ value: part.value,
55
+ });
56
+ parent.children.splice(index, 1, ...newNodes);
57
+ };
58
+ //# sourceMappingURL=badge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"badge.js","sourceRoot":"","sources":["../../src/transforms/badge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AAExB,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAA;AAEzC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,eAAe,CA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QAAE,OAAM;IACxE,IACE,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9C,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC3B,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CACxD,EACD,CAAC;QACD,OAAM;IACR,CAAC;IAED,MAAM,QAAQ,GAAG,IAAY,CAAA;IAC7B,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IACnE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC;QAAE,OAAM;IAE5D,MAAM,QAAQ,GAAiC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAChE,IAAI,CAAC,IAAI,KAAK,WAAW;QACvB,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC;QAC3C,CAAC,CAAC;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CACN,CAEA;IAAC,MAAM,CAAC,QAAmB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAI,QAAmB,CAAC,CAAA;AACxE,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-cell-list/build-table-cell-children";
2
+ //# sourceMappingURL=build-table-cell-children.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-table-cell-children.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/build-table-cell-children.ts"],"names":[],"mappings":"AACA,cAAc,sEAAsE,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-cell-list/build-table-cell-children";
3
+ //# sourceMappingURL=build-table-cell-children.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-table-cell-children.js","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/build-table-cell-children.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,sEAAsE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-cell-list/elements";
2
+ //# sourceMappingURL=elements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/elements.ts"],"names":[],"mappings":"AACA,cAAc,qDAAqD,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-cell-list/elements";
3
+ //# sourceMappingURL=elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.js","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/elements.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,qDAAqD,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-cell-list/index";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/index.ts"],"names":[],"mappings":"AACA,cAAc,kDAAkD,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-cell-list/index";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,kDAAkD,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-cell-list/nodes";
2
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/nodes.ts"],"names":[],"mappings":"AACA,cAAc,kDAAkD,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-cell-list/nodes";
3
+ //# sourceMappingURL=nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/nodes.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,kDAAkD,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-cell-list/parse-inline-markdown";
2
+ //# sourceMappingURL=parse-inline-markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-inline-markdown.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/parse-inline-markdown.ts"],"names":[],"mappings":"AACA,cAAc,kEAAkE,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-cell-list/parse-inline-markdown";
3
+ //# sourceMappingURL=parse-inline-markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-inline-markdown.js","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/parse-inline-markdown.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,kEAAkE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-cell-list/parse-table-cell-list";
2
+ //# sourceMappingURL=parse-table-cell-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-table-cell-list.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/parse-table-cell-list.ts"],"names":[],"mappings":"AACA,cAAc,kEAAkE,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-cell-list/parse-table-cell-list";
3
+ //# sourceMappingURL=parse-table-cell-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-table-cell-list.js","sourceRoot":"","sources":["../../../src/transforms/table-cell-list/parse-table-cell-list.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,kEAAkE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-column-layout/create-table";
2
+ //# sourceMappingURL=create-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-table.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-column-layout/create-table.ts"],"names":[],"mappings":"AACA,cAAc,6DAA6D,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-column-layout/create-table";
3
+ //# sourceMappingURL=create-table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-table.js","sourceRoot":"","sources":["../../../src/transforms/table-column-layout/create-table.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,6DAA6D,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-column-layout/index";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/table-column-layout/index.ts"],"names":[],"mappings":"AACA,cAAc,sDAAsD,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Compatibility entrypoint. The implementation is shared by all hosts.
2
+ export * from "@cudoment/cudoc/transforms/table-column-layout/index";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transforms/table-column-layout/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,cAAc,sDAAsD,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@cudoment/cudoc/transforms/table-column-layout/split-cell";
2
+ //# sourceMappingURL=split-cell.d.ts.map