@xyd-js/content 0.1.0-xyd.4 → 0.1.0-xyd.55
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/CHANGELOG.md +628 -0
- package/ISSUES.md +1 -0
- package/LICENSE +21 -0
- package/TODO.md +2 -0
- package/dist/index.d.ts +27 -1733
- package/dist/index.js +1602 -179
- package/dist/index.js.map +1 -0
- package/dist/md.d.ts +69 -0
- package/dist/md.js +23396 -0
- package/dist/md.js.map +1 -0
- package/dist/mdToc-NBBxMJ4l.d.ts +12 -0
- package/dist/vite.d.ts +1066 -0
- package/dist/vite.js +20046 -0
- package/dist/vite.js.map +1 -0
- package/package.json +27 -7
- package/packages/md/index.ts +22 -0
- package/packages/md/plugins/component-directives/index.ts +3 -0
- package/packages/md/plugins/component-directives/mdComponentDirective.ts +524 -0
- package/packages/md/plugins/component-directives/types.ts +1 -0
- package/packages/md/plugins/component-directives/utils.ts +27 -0
- package/packages/md/plugins/composer/__fixtures__/1.single-example/input.md +7 -0
- package/packages/md/plugins/composer/__fixtures__/1.single-example/output.json +63 -0
- package/packages/md/plugins/composer/__fixtures__/2.single-example-with-name/input.md +7 -0
- package/packages/md/plugins/composer/__fixtures__/2.single-example-with-name/output.json +63 -0
- package/packages/md/plugins/composer/__fixtures__/3.multiple-examples/input.md +15 -0
- package/packages/md/plugins/composer/__fixtures__/3.multiple-examples/output.json +122 -0
- package/packages/md/plugins/composer/__fixtures__/4.example-groups/input.md +23 -0
- package/packages/md/plugins/composer/__fixtures__/4.example-groups/output.json +184 -0
- package/packages/md/plugins/composer/__tests__/mdComposer.test.ts +41 -0
- package/packages/md/plugins/composer/__tests__/testHelpers.ts +48 -0
- package/packages/md/plugins/composer/index.ts +1 -0
- package/packages/md/plugins/composer/mdComposer.ts +146 -0
- package/packages/md/plugins/developer-writing/index.ts +3 -0
- package/packages/md/plugins/developer-writing/mdCodeRehype.ts +78 -0
- package/packages/md/plugins/functions/__fixtures__/external.ts +4 -0
- package/packages/md/plugins/functions/__fixtures__/test.js +11 -0
- package/packages/md/plugins/functions/__fixtures__/test.py +9 -0
- package/packages/md/plugins/functions/__fixtures__/test.ts +18 -0
- package/packages/md/plugins/functions/__tests__/mdFunctionImportCode.test.ts +295 -0
- package/packages/md/plugins/functions/__tests__/parseFunctionCall.test.ts +47 -0
- package/packages/md/plugins/functions/__tests__/testHelpers.ts +71 -0
- package/packages/md/plugins/functions/index.ts +11 -0
- package/packages/md/plugins/functions/mdFunctionChangelog.ts +124 -0
- package/packages/md/plugins/functions/mdFunctionImportCode.ts +83 -0
- package/packages/md/plugins/functions/mdFunctionUniform.ts +79 -0
- package/packages/md/plugins/functions/types.ts +6 -0
- package/packages/md/plugins/functions/uniformProcessor.ts +349 -0
- package/packages/md/plugins/functions/utils.ts +423 -0
- package/packages/md/plugins/index.ts +71 -0
- package/packages/md/plugins/mdCode.ts +67 -0
- package/packages/md/plugins/mdHeadingId.ts +47 -0
- package/packages/md/plugins/mdPage.ts +35 -0
- package/{src/mdx/themeSettings.ts → packages/md/plugins/mdThemeSettings.ts} +8 -0
- package/packages/md/plugins/mdToc.ts +224 -0
- package/packages/md/plugins/meta/index.ts +1 -0
- package/packages/md/plugins/meta/mdMeta.ts +189 -0
- package/packages/md/plugins/output-variables/__fixtures__/1.simple/input.md +22 -0
- package/packages/md/plugins/output-variables/__fixtures__/1.simple/output.json +191 -0
- package/packages/md/plugins/output-variables/__fixtures__/2.multiple-vars/input.md +21 -0
- package/packages/md/plugins/output-variables/__fixtures__/2.multiple-vars/output.json +127 -0
- package/packages/md/plugins/output-variables/__tests__/index.test.ts +28 -0
- package/packages/md/plugins/output-variables/__tests__/testHelpers.ts +36 -0
- package/packages/md/plugins/output-variables/index.ts +1 -0
- package/packages/md/plugins/output-variables/lib/const.ts +4 -0
- package/packages/md/plugins/output-variables/lib/factoryAttributes.ts +350 -0
- package/packages/md/plugins/output-variables/lib/factoryLabel.ts +135 -0
- package/packages/md/plugins/output-variables/lib/factoryName.ts +59 -0
- package/packages/md/plugins/output-variables/lib/index.ts +21 -0
- package/packages/md/plugins/output-variables/lib/outputVarsContainer.ts +328 -0
- package/packages/md/plugins/output-variables/lib/util.ts +494 -0
- package/packages/md/plugins/output-variables/remarkOutputVars.ts +22 -0
- package/packages/md/plugins/rehypeHeading.ts +50 -0
- package/packages/md/plugins/types.ts +15 -0
- package/packages/md/plugins/utils/componentLike.ts +72 -0
- package/packages/md/plugins/utils/index.ts +2 -0
- package/packages/md/plugins/utils/mdParameters.test.ts +114 -0
- package/packages/md/plugins/utils/mdParameters.ts +249 -0
- package/packages/md/plugins/utils/mdastTypes.ts +42 -0
- package/packages/md/search/index.ts +251 -0
- package/packages/md/search/types.ts +36 -0
- package/{src/vite-plugins → packages/vite}/index.ts +8 -3
- package/src/fs.ts +58 -0
- package/src/index.ts +8 -0
- package/src/{navigation/index.ts → navigation.ts} +54 -58
- package/src/types.ts +8 -0
- package/tsconfig.json +31 -8
- package/tsup.config.ts +8 -6
- package/vitest.config.ts +17 -0
- package/dist/navigation.d.ts +0 -6
- package/dist/navigation.js +0 -2345
- package/index.ts +0 -10
- package/navigation.ts +0 -4
- package/src/mdx/code.ts +0 -15
- package/src/mdx/options.ts +0 -23
- package/src/mdx/page.ts +0 -22
- package/src/mdx/toc.ts +0 -132
- package/src/utils/index.ts +0 -43
- package/vite.config.js +0 -53
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { Root, Heading } from "mdast";
|
|
2
|
+
import { MdxjsEsm } from "mdast-util-mdx";
|
|
3
|
+
import { Plugin } from "unified";
|
|
4
|
+
import { MdxJsxFlowElement, MdxJsxAttribute } from "mdast-util-mdx-jsx";
|
|
5
|
+
|
|
6
|
+
import { mdParameters } from './utils/mdParameters';
|
|
7
|
+
|
|
8
|
+
export type TocEntry = {
|
|
9
|
+
depth: number,
|
|
10
|
+
id: string,
|
|
11
|
+
value: string,
|
|
12
|
+
attributes: { [key: string]: string },
|
|
13
|
+
children: TocEntry[],
|
|
14
|
+
maxTocDepth?: number
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type CustomTag = {
|
|
18
|
+
name: RegExp,
|
|
19
|
+
depth: (name: string) => number
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface RemarkMdxTocOptions {
|
|
23
|
+
name?: string,
|
|
24
|
+
customTags?: CustomTag[],
|
|
25
|
+
maxDepth?: number,
|
|
26
|
+
minDepth?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// TODO: fix any
|
|
30
|
+
export const remarkMdxToc = (options: RemarkMdxTocOptions): Plugin => () => async (ast: any) => {
|
|
31
|
+
if (!options?.minDepth) {
|
|
32
|
+
options.minDepth = 2
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.time('plugin:remarkMdxToc');
|
|
36
|
+
const { visit } = await import("unist-util-visit");
|
|
37
|
+
const { toString } = await import("mdast-util-to-string");
|
|
38
|
+
const { valueToEstree } = await import('estree-util-value-to-estree')
|
|
39
|
+
const { name: isIdentifierName } = await import('estree-util-is-identifier-name');
|
|
40
|
+
|
|
41
|
+
const mdast = ast as Root;
|
|
42
|
+
const name = options.name ?? "toc";
|
|
43
|
+
if (!isIdentifierName(name)) {
|
|
44
|
+
throw new Error(`Invalid name for an identifier: ${name}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const toc: TocEntry[] = [];
|
|
48
|
+
const flatToc: TocEntry[] = [];
|
|
49
|
+
const nodesToRemove: number[] = [];
|
|
50
|
+
|
|
51
|
+
const createEntry = (node: Heading | MdxJsxFlowElement, depth: number, index: number): TocEntry | null => {
|
|
52
|
+
let attributes = (node.data || {}) as TocEntry['attributes'];
|
|
53
|
+
if (node.type === "mdxJsxFlowElement") {
|
|
54
|
+
attributes = Object.fromEntries(
|
|
55
|
+
node.attributes
|
|
56
|
+
.filter(attribute => attribute.type === 'mdxJsxAttribute' && typeof attribute.value === 'string')
|
|
57
|
+
.map(attribute => [(attribute as MdxJsxAttribute).name, attribute.value])
|
|
58
|
+
) as TocEntry['attributes'];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let value = toString(node, { includeImageAlt: false });
|
|
62
|
+
const { attributes: parsedAttributes, sanitizedText } = mdParameters(value);
|
|
63
|
+
|
|
64
|
+
// Merge parsed attributes with existing ones
|
|
65
|
+
attributes = { ...attributes, ...parsedAttributes };
|
|
66
|
+
|
|
67
|
+
// Handle toc attribute
|
|
68
|
+
if (attributes.toc === 'false') {
|
|
69
|
+
return null; // Skip this entry
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// If toc attribute is present, update the node's content to remove the [toc] part
|
|
73
|
+
if (attributes.toc === 'true' && node.type === "heading") {
|
|
74
|
+
// Keep the heading but remove the [toc] text and hide it
|
|
75
|
+
(node as any).data = {
|
|
76
|
+
...(node as any).data,
|
|
77
|
+
hProperties: {
|
|
78
|
+
...(node as any).data?.hProperties,
|
|
79
|
+
hideHeading: true
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
node.children = node.children.map(child => {
|
|
83
|
+
if (child.type === "text") {
|
|
84
|
+
return {
|
|
85
|
+
...child,
|
|
86
|
+
value: ""
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return child;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Use toc value if provided, otherwise use clean text
|
|
94
|
+
const tocValue = attributes.toc === 'true' ? sanitizedText : (attributes.toc || sanitizedText);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
depth,
|
|
98
|
+
id: (node.data as any)?.hProperties?.id,
|
|
99
|
+
value: tocValue,
|
|
100
|
+
attributes,
|
|
101
|
+
children: [],
|
|
102
|
+
maxTocDepth: attributes.maxTocDepth ? parseInt(attributes.maxTocDepth) : undefined
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
visit(mdast, ["heading", "mdxJsxFlowElement"], (node, index) => {
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
let depth = 0;
|
|
109
|
+
if (node.type === "mdxJsxFlowElement") {
|
|
110
|
+
let valid = false;
|
|
111
|
+
if (/^h[1-6]$/.test(node.name || "")) {
|
|
112
|
+
valid = true;
|
|
113
|
+
depth = parseInt(node.name!.substring(1));
|
|
114
|
+
} else if (options.customTags) {
|
|
115
|
+
for (const tag of options.customTags) {
|
|
116
|
+
if (tag.name.test(node.name || "")) {
|
|
117
|
+
valid = true;
|
|
118
|
+
depth = tag.depth(node.name || "");
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!valid) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
} else if (node.type === "heading") {
|
|
128
|
+
depth = node.depth;
|
|
129
|
+
} else {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const entry = createEntry(node, depth, index as number);
|
|
134
|
+
if (!entry) return;
|
|
135
|
+
|
|
136
|
+
// If toc attribute is explicitly set to true or +toc is present, include it regardless of depth
|
|
137
|
+
if (entry.attributes.toc === 'true' || entry.attributes["+toc"] === 'true') {
|
|
138
|
+
flatToc.push(entry);
|
|
139
|
+
let parent: TocEntry[] = toc;
|
|
140
|
+
for (let i = flatToc.length - 1; i >= 0; --i) {
|
|
141
|
+
const current = flatToc[i];
|
|
142
|
+
if (current.depth < entry.depth) {
|
|
143
|
+
parent = current.children;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
parent.push(entry);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// First check if this entry should be included based on parent's maxTocDepth
|
|
152
|
+
let parentMaxDepth = options.maxDepth;
|
|
153
|
+
for (let i = flatToc.length - 1; i >= 0; --i) {
|
|
154
|
+
const parent = flatToc[i];
|
|
155
|
+
if (parent.depth < entry.depth) {
|
|
156
|
+
if (parent.maxTocDepth !== undefined) {
|
|
157
|
+
parentMaxDepth = parent.maxTocDepth;
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Now check against the effective max depth (either global or parent's maxTocDepth)
|
|
164
|
+
if (depth && parentMaxDepth && depth > parentMaxDepth) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (depth && (options?.minDepth && depth < options.minDepth)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
flatToc.push(entry);
|
|
173
|
+
|
|
174
|
+
let parent: TocEntry[] = toc;
|
|
175
|
+
for (let i = flatToc.length - 1; i >= 0; --i) {
|
|
176
|
+
const current = flatToc[i];
|
|
177
|
+
if (current.depth < entry.depth) {
|
|
178
|
+
parent = current.children;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
parent.push(entry);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Remove nodes marked for removal
|
|
186
|
+
nodesToRemove.sort((a, b) => b - a).forEach(index => {
|
|
187
|
+
mdast.children.splice(index, 1);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const tocExport: MdxjsEsm = {
|
|
191
|
+
type: "mdxjsEsm",
|
|
192
|
+
value: "",
|
|
193
|
+
data: {
|
|
194
|
+
estree: {
|
|
195
|
+
type: "Program",
|
|
196
|
+
sourceType: "module",
|
|
197
|
+
body: [
|
|
198
|
+
{
|
|
199
|
+
type: "ExportNamedDeclaration",
|
|
200
|
+
specifiers: [],
|
|
201
|
+
attributes: [],
|
|
202
|
+
source: null,
|
|
203
|
+
declaration: {
|
|
204
|
+
type: "VariableDeclaration",
|
|
205
|
+
kind: "const",
|
|
206
|
+
declarations: [
|
|
207
|
+
{
|
|
208
|
+
type: "VariableDeclarator",
|
|
209
|
+
id: {
|
|
210
|
+
type: "Identifier",
|
|
211
|
+
name
|
|
212
|
+
},
|
|
213
|
+
init: valueToEstree(toc)
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
mdast.children.unshift(tocExport);
|
|
223
|
+
console.timeEnd('plugin:remarkMdxToc');
|
|
224
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mdMeta } from "./mdMeta";
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Root } from 'mdast';
|
|
2
|
+
import { matter } from 'vfile-matter';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { Metadata, Settings, Theme } from '@xyd-js/core';
|
|
6
|
+
import { getMetaComponent } from '@xyd-js/context';
|
|
7
|
+
import { Reference, TypeDocReferenceContext } from '@xyd-js/uniform';
|
|
8
|
+
import { uniformToMiniUniform } from '@xyd-js/sources/ts';
|
|
9
|
+
|
|
10
|
+
import { FunctionName } from '../functions/types';
|
|
11
|
+
import { parseFunctionCall, parseImportPath } from '../functions/utils';
|
|
12
|
+
import { processUniformFunctionCall } from '../functions/uniformProcessor';
|
|
13
|
+
import { componentLike } from '../utils';
|
|
14
|
+
import { SymbolxVfile } from '../types';
|
|
15
|
+
|
|
16
|
+
export interface MdMetaOptions {
|
|
17
|
+
resolveFrom?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// TODO: IT SHOULD BE PART OF COMPOSER
|
|
21
|
+
|
|
22
|
+
export function mdMeta(settings?: Settings, options?: MdMetaOptions) {
|
|
23
|
+
return function() {
|
|
24
|
+
return async (tree: Root, file: SymbolxVfile<any>) => {
|
|
25
|
+
console.time('plugin:mdMeta:total');
|
|
26
|
+
console.time('plugin:mdMeta:frontmatter');
|
|
27
|
+
// Parse frontmatter and expose it at file.data.matter
|
|
28
|
+
matter(file as any);
|
|
29
|
+
console.timeEnd('plugin:mdMeta:frontmatter');
|
|
30
|
+
|
|
31
|
+
if (!file.data.matter) {
|
|
32
|
+
console.timeEnd('plugin:mdMeta:total');
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.time('plugin:mdMeta:metaProcessing');
|
|
37
|
+
const meta = file.data.matter as Metadata<Record<string, any>>
|
|
38
|
+
if (!meta) {
|
|
39
|
+
console.timeEnd('plugin:mdMeta:metaProcessing');
|
|
40
|
+
console.timeEnd('plugin:mdMeta:total');
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (meta?.uniform || meta?.openapi || meta?.graphql) {
|
|
45
|
+
if (meta.graphql) {
|
|
46
|
+
meta.uniform = meta.graphql
|
|
47
|
+
} else if (meta.openapi) {
|
|
48
|
+
meta.uniform = meta.openapi
|
|
49
|
+
}
|
|
50
|
+
meta.component = "atlas"
|
|
51
|
+
|
|
52
|
+
if (typeof meta.uniform === "string") {
|
|
53
|
+
meta.componentProps = {
|
|
54
|
+
references: `@uniform('${meta.uniform}')`
|
|
55
|
+
}
|
|
56
|
+
} else if (typeof meta.uniform === "object") {
|
|
57
|
+
const uniformArgs = {}
|
|
58
|
+
|
|
59
|
+
if (meta.uniform.eager) {
|
|
60
|
+
// TODO: support eager line ranges?
|
|
61
|
+
const { filePath, regions } = parseImportPath(meta.uniform.path)
|
|
62
|
+
|
|
63
|
+
if (regions.length > 1) {
|
|
64
|
+
console.warn("Eager uniform with multiple regions is not supported")
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (regions.length) {
|
|
68
|
+
uniformArgs["eager"] = regions[0].name
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
meta.uniform.path = filePath
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
meta.componentProps = {
|
|
75
|
+
references: `@uniform('${meta.uniform.path}', ${JSON.stringify(uniformArgs)})`
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!meta || !meta.component) {
|
|
81
|
+
console.timeEnd('plugin:mdMeta:metaProcessing');
|
|
82
|
+
console.timeEnd('plugin:mdMeta:total');
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const metaComponent = getMetaComponent(meta.component)
|
|
87
|
+
|
|
88
|
+
if (!metaComponent) {
|
|
89
|
+
console.timeEnd('plugin:mdMeta:metaProcessing');
|
|
90
|
+
console.timeEnd('plugin:mdMeta:total');
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
console.timeEnd('plugin:mdMeta:metaProcessing');
|
|
94
|
+
|
|
95
|
+
console.time('plugin:mdMeta:propsProcessing');
|
|
96
|
+
const promises: Promise<void>[] = []
|
|
97
|
+
|
|
98
|
+
let resolvedProps: Record<string, any> = {}
|
|
99
|
+
if (meta.componentProps && typeof meta.componentProps === "object") {
|
|
100
|
+
for (const key in meta.componentProps) { // TODO: support nested props
|
|
101
|
+
const value = meta.componentProps[key]
|
|
102
|
+
|
|
103
|
+
const result = parseFunctionCall({
|
|
104
|
+
children: [
|
|
105
|
+
{
|
|
106
|
+
type: "text",
|
|
107
|
+
value: value
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}, FunctionName.Uniform);
|
|
111
|
+
|
|
112
|
+
if (!result) {
|
|
113
|
+
resolvedProps[key] = value
|
|
114
|
+
continue
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const importPath = result[0]
|
|
118
|
+
const importArgs = result[1];
|
|
119
|
+
|
|
120
|
+
if (!importPath) {
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const promise = (async () => {
|
|
125
|
+
let references = await processUniformFunctionCall(
|
|
126
|
+
importPath,
|
|
127
|
+
file,
|
|
128
|
+
options?.resolveFrom,
|
|
129
|
+
settings,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if (importArgs?.eager && references) { // TODO: move to `processUniformFunctionCall`
|
|
134
|
+
// TODO: rename uniformToMiniUniform eager
|
|
135
|
+
// TODO: support multile regions
|
|
136
|
+
references = uniformToMiniUniform(importArgs.eager, references as Reference<TypeDocReferenceContext>[]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resolvedProps[key] = references
|
|
140
|
+
})()
|
|
141
|
+
|
|
142
|
+
promises.push(promise)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await Promise.all(promises)
|
|
147
|
+
console.timeEnd('plugin:mdMeta:propsProcessing');
|
|
148
|
+
|
|
149
|
+
console.time('plugin:mdMeta:transform');
|
|
150
|
+
const resolvedComponentProps = await metaComponent.transform(
|
|
151
|
+
(settings?.theme || {}) as Theme,
|
|
152
|
+
resolvedProps,
|
|
153
|
+
file.data.outputVars,
|
|
154
|
+
Object.freeze(tree.children) as any
|
|
155
|
+
)
|
|
156
|
+
console.timeEnd('plugin:mdMeta:transform');
|
|
157
|
+
|
|
158
|
+
console.time('plugin:mdMeta:componentCreation');
|
|
159
|
+
const exportNode = componentLike(
|
|
160
|
+
metaComponent.componentName,
|
|
161
|
+
resolvedComponentProps,
|
|
162
|
+
[]
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
tree.children = [
|
|
166
|
+
...treeSanitize(tree),
|
|
167
|
+
...exportNode.children
|
|
168
|
+
]
|
|
169
|
+
console.timeEnd('plugin:mdMeta:componentCreation');
|
|
170
|
+
console.timeEnd('plugin:mdMeta:total');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// TODO: add more / BETTER SOLUTION FOR CLEARIN
|
|
176
|
+
const allowedNodes = [
|
|
177
|
+
"mdxjsEsm",
|
|
178
|
+
// "outputVars", // TODO: !!! cuz some issues with outputvars + containerDirective !!!
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
function treeSanitize(tree: Root) {
|
|
182
|
+
return tree.children.filter((child) => {
|
|
183
|
+
if (allowedNodes.includes(child.type)) {
|
|
184
|
+
return true
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return false
|
|
188
|
+
})
|
|
189
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "root",
|
|
3
|
+
"children": [
|
|
4
|
+
{
|
|
5
|
+
"type": "heading",
|
|
6
|
+
"depth": 1,
|
|
7
|
+
"children": [
|
|
8
|
+
{
|
|
9
|
+
"type": "text",
|
|
10
|
+
"value": "Heading 1",
|
|
11
|
+
"position": {
|
|
12
|
+
"start": {
|
|
13
|
+
"line": 1,
|
|
14
|
+
"column": 3,
|
|
15
|
+
"offset": 2
|
|
16
|
+
},
|
|
17
|
+
"end": {
|
|
18
|
+
"line": 1,
|
|
19
|
+
"column": 12,
|
|
20
|
+
"offset": 11
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"position": {
|
|
26
|
+
"start": {
|
|
27
|
+
"line": 1,
|
|
28
|
+
"column": 1,
|
|
29
|
+
"offset": 0
|
|
30
|
+
},
|
|
31
|
+
"end": {
|
|
32
|
+
"line": 1,
|
|
33
|
+
"column": 12,
|
|
34
|
+
"offset": 11
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"type": "outputVars",
|
|
40
|
+
"name": "example",
|
|
41
|
+
"attributes": {},
|
|
42
|
+
"children": [
|
|
43
|
+
{
|
|
44
|
+
"type": "code",
|
|
45
|
+
"lang": "bash",
|
|
46
|
+
"meta": "npm",
|
|
47
|
+
"value": "npm i -g xyd-js",
|
|
48
|
+
"position": {
|
|
49
|
+
"start": {
|
|
50
|
+
"line": 5,
|
|
51
|
+
"column": 3,
|
|
52
|
+
"offset": 27
|
|
53
|
+
},
|
|
54
|
+
"end": {
|
|
55
|
+
"line": 7,
|
|
56
|
+
"column": 6,
|
|
57
|
+
"offset": 62
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"type": "code",
|
|
63
|
+
"lang": "bash",
|
|
64
|
+
"meta": "yarn",
|
|
65
|
+
"value": "yarn global add xyd-js",
|
|
66
|
+
"position": {
|
|
67
|
+
"start": {
|
|
68
|
+
"line": 9,
|
|
69
|
+
"column": 3,
|
|
70
|
+
"offset": 66
|
|
71
|
+
},
|
|
72
|
+
"end": {
|
|
73
|
+
"line": 11,
|
|
74
|
+
"column": 6,
|
|
75
|
+
"offset": 109
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "code",
|
|
81
|
+
"lang": "bash",
|
|
82
|
+
"meta": "pnpm",
|
|
83
|
+
"value": "pnpm add -g xyd-js",
|
|
84
|
+
"position": {
|
|
85
|
+
"start": {
|
|
86
|
+
"line": 13,
|
|
87
|
+
"column": 3,
|
|
88
|
+
"offset": 113
|
|
89
|
+
},
|
|
90
|
+
"end": {
|
|
91
|
+
"line": 15,
|
|
92
|
+
"column": 6,
|
|
93
|
+
"offset": 152
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"position": {
|
|
99
|
+
"start": {
|
|
100
|
+
"line": 4,
|
|
101
|
+
"column": 1,
|
|
102
|
+
"offset": 14
|
|
103
|
+
},
|
|
104
|
+
"end": {
|
|
105
|
+
"line": 16,
|
|
106
|
+
"column": 4,
|
|
107
|
+
"offset": 156
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"type": "heading",
|
|
113
|
+
"depth": 2,
|
|
114
|
+
"children": [
|
|
115
|
+
{
|
|
116
|
+
"type": "text",
|
|
117
|
+
"value": "Heading 2",
|
|
118
|
+
"position": {
|
|
119
|
+
"start": {
|
|
120
|
+
"line": 18,
|
|
121
|
+
"column": 4,
|
|
122
|
+
"offset": 161
|
|
123
|
+
},
|
|
124
|
+
"end": {
|
|
125
|
+
"line": 18,
|
|
126
|
+
"column": 13,
|
|
127
|
+
"offset": 170
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
"position": {
|
|
133
|
+
"start": {
|
|
134
|
+
"line": 18,
|
|
135
|
+
"column": 1,
|
|
136
|
+
"offset": 158
|
|
137
|
+
},
|
|
138
|
+
"end": {
|
|
139
|
+
"line": 18,
|
|
140
|
+
"column": 13,
|
|
141
|
+
"offset": 170
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "paragraph",
|
|
147
|
+
"children": [
|
|
148
|
+
{
|
|
149
|
+
"type": "text",
|
|
150
|
+
"value": "Lorem ipsum",
|
|
151
|
+
"position": {
|
|
152
|
+
"start": {
|
|
153
|
+
"line": 20,
|
|
154
|
+
"column": 1,
|
|
155
|
+
"offset": 172
|
|
156
|
+
},
|
|
157
|
+
"end": {
|
|
158
|
+
"line": 20,
|
|
159
|
+
"column": 12,
|
|
160
|
+
"offset": 183
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"position": {
|
|
166
|
+
"start": {
|
|
167
|
+
"line": 20,
|
|
168
|
+
"column": 1,
|
|
169
|
+
"offset": 172
|
|
170
|
+
},
|
|
171
|
+
"end": {
|
|
172
|
+
"line": 20,
|
|
173
|
+
"column": 12,
|
|
174
|
+
"offset": 183
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
"position": {
|
|
180
|
+
"start": {
|
|
181
|
+
"line": 1,
|
|
182
|
+
"column": 1,
|
|
183
|
+
"offset": 0
|
|
184
|
+
},
|
|
185
|
+
"end": {
|
|
186
|
+
"line": 23,
|
|
187
|
+
"column": 1,
|
|
188
|
+
"offset": 186
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<<<example
|
|
2
|
+
```bash npm
|
|
3
|
+
npm i -g xyd-js
|
|
4
|
+
```
|
|
5
|
+
|
|
6
|
+
```bash yarn
|
|
7
|
+
yarn global add xyd-js
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```bash pnpm
|
|
11
|
+
pnpm add -g xyd-js
|
|
12
|
+
```
|
|
13
|
+
<<<
|
|
14
|
+
|
|
15
|
+
<<<example2
|
|
16
|
+
```tsx
|
|
17
|
+
function() {
|
|
18
|
+
return <div> Hello World </div>
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
<<<
|