@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
package/index.ts
DELETED
package/navigation.ts
DELETED
package/src/mdx/code.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {visit} from "unist-util-visit";
|
|
2
|
-
|
|
3
|
-
export function remarkInjectCodeMeta() {
|
|
4
|
-
return (tree: any) => {
|
|
5
|
-
visit(tree, 'code', (node) => {
|
|
6
|
-
if (node.meta) {
|
|
7
|
-
node.data = node.data || {};
|
|
8
|
-
node.data.hProperties = {
|
|
9
|
-
...(node.data.hProperties || {}),
|
|
10
|
-
meta: node.meta,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
}
|
package/src/mdx/options.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import remarkFrontmatter from "remark-frontmatter";
|
|
2
|
-
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
3
|
-
import remarkGfm from "remark-gfm";
|
|
4
|
-
|
|
5
|
-
import {remarkMdxToc, RemarkMdxTocOptions} from "@/mdx/toc";
|
|
6
|
-
import {remarkInjectCodeMeta} from "@/mdx/code";
|
|
7
|
-
import {extractThemeSettings} from "@/mdx/themeSettings";
|
|
8
|
-
import {extractPage} from "@/mdx/page";
|
|
9
|
-
|
|
10
|
-
export function mdxOptions(toc: RemarkMdxTocOptions) {
|
|
11
|
-
return {
|
|
12
|
-
remarkPlugins: [
|
|
13
|
-
remarkFrontmatter,
|
|
14
|
-
remarkMdxFrontmatter,
|
|
15
|
-
remarkGfm,
|
|
16
|
-
remarkInjectCodeMeta,
|
|
17
|
-
remarkMdxToc(toc),
|
|
18
|
-
extractThemeSettings,
|
|
19
|
-
extractPage
|
|
20
|
-
],
|
|
21
|
-
rehypePlugins: []
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/mdx/page.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {Plugin} from 'unified';
|
|
2
|
-
import {Node as UnistNode} from 'unist';
|
|
3
|
-
import {visit} from 'unist-util-visit';
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
var page: boolean | null | undefined
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const extractPage: Plugin = () => {
|
|
10
|
-
return (tree: UnistNode) => {
|
|
11
|
-
visit(tree, 'exportNamedDeclaration', (node: any) => {
|
|
12
|
-
const declaration = node.declaration;
|
|
13
|
-
if (declaration && declaration.declarations) {
|
|
14
|
-
declaration.declarations.forEach((decl: any) => {
|
|
15
|
-
if (decl.id.name === 'page') {
|
|
16
|
-
global.page = decl.init as boolean;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
};
|
package/src/mdx/toc.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {Root, Heading} from "mdast";
|
|
2
|
-
import {MdxjsEsm} from "mdast-util-mdx";
|
|
3
|
-
import {Plugin} from "unified"; // TODO: use Plugin type
|
|
4
|
-
import {MdxJsxFlowElement, MdxJsxAttribute} from "mdast-util-mdx-jsx";
|
|
5
|
-
|
|
6
|
-
export type TocEntry = {
|
|
7
|
-
depth: number,
|
|
8
|
-
value: string,
|
|
9
|
-
attributes: { [key: string]: string },
|
|
10
|
-
children: TocEntry[]
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type CustomTag = {
|
|
14
|
-
name: RegExp,
|
|
15
|
-
depth: (name: string) => number
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export interface RemarkMdxTocOptions {
|
|
19
|
-
name?: string,
|
|
20
|
-
customTags?: CustomTag[],
|
|
21
|
-
minDepth?: number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// TODO: fix any
|
|
25
|
-
export const remarkMdxToc = (options: RemarkMdxTocOptions): Plugin => () => async (ast: any) => {
|
|
26
|
-
const {visit} = await import("unist-util-visit");
|
|
27
|
-
const {toString} = await import("mdast-util-to-string");
|
|
28
|
-
const {valueToEstree} = await import('estree-util-value-to-estree')
|
|
29
|
-
const {name: isIdentifierName} = await import('estree-util-is-identifier-name');
|
|
30
|
-
|
|
31
|
-
const mdast = ast as Root;
|
|
32
|
-
const name = options.name ?? "toc";
|
|
33
|
-
if (!isIdentifierName(name)) {
|
|
34
|
-
throw new Error(`Invalid name for an identifier: ${name}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const toc: TocEntry[] = [];
|
|
38
|
-
const flatToc: TocEntry[] = [];
|
|
39
|
-
const createEntry = (node: Heading | MdxJsxFlowElement, depth: number): TocEntry => {
|
|
40
|
-
let attributes = (node.data || {}) as TocEntry['attributes'];
|
|
41
|
-
if (node.type === "mdxJsxFlowElement") {
|
|
42
|
-
attributes = Object.fromEntries(
|
|
43
|
-
node.attributes
|
|
44
|
-
.filter(attribute => attribute.type === 'mdxJsxAttribute' && typeof attribute.value === 'string')
|
|
45
|
-
.map(attribute => [(attribute as MdxJsxAttribute).name, attribute.value])
|
|
46
|
-
) as TocEntry['attributes'];
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
depth,
|
|
50
|
-
value: toString(node, {includeImageAlt: false}),
|
|
51
|
-
attributes,
|
|
52
|
-
children: []
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
visit(mdast, ["heading", "mdxJsxFlowElement"], node => {
|
|
57
|
-
let depth = 0;
|
|
58
|
-
if (node.type === "mdxJsxFlowElement") {
|
|
59
|
-
let valid = false;
|
|
60
|
-
if (/^h[1-6]$/.test(node.name || "")) {
|
|
61
|
-
valid = true;
|
|
62
|
-
depth = parseInt(node.name!.substring(1));
|
|
63
|
-
} else if (options.customTags) {
|
|
64
|
-
for (const tag of options.customTags) {
|
|
65
|
-
if (tag.name.test(node.name || "")) {
|
|
66
|
-
valid = true;
|
|
67
|
-
depth = tag.depth(node.name || "");
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!valid) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
} else if (node.type === "heading") {
|
|
77
|
-
depth = node.depth;
|
|
78
|
-
} else {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (depth && (options?.minDepth && options.minDepth > depth)) {
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const entry = createEntry(node, depth);
|
|
87
|
-
flatToc.push(entry);
|
|
88
|
-
|
|
89
|
-
let parent: TocEntry[] = toc;
|
|
90
|
-
for (let i = flatToc.length - 1; i >= 0; --i) {
|
|
91
|
-
const current = flatToc[i];
|
|
92
|
-
if (current.depth < entry.depth) {
|
|
93
|
-
parent = current.children;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
parent.push(entry);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const tocExport: MdxjsEsm = {
|
|
101
|
-
type: "mdxjsEsm",
|
|
102
|
-
value: "",
|
|
103
|
-
data: {
|
|
104
|
-
estree: {
|
|
105
|
-
type: "Program",
|
|
106
|
-
sourceType: "module",
|
|
107
|
-
body: [
|
|
108
|
-
{
|
|
109
|
-
type: "ExportNamedDeclaration",
|
|
110
|
-
specifiers: [],
|
|
111
|
-
source: null,
|
|
112
|
-
declaration: {
|
|
113
|
-
type: "VariableDeclaration",
|
|
114
|
-
kind: "const",
|
|
115
|
-
declarations: [
|
|
116
|
-
{
|
|
117
|
-
type: "VariableDeclarator",
|
|
118
|
-
id: {
|
|
119
|
-
type: "Identifier",
|
|
120
|
-
name
|
|
121
|
-
},
|
|
122
|
-
init: valueToEstree(toc)
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
]
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
mdast.children.unshift(tocExport);
|
|
132
|
-
};
|
package/src/utils/index.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {promises as fs} from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
import {VFile} from "vfile";
|
|
5
|
-
import {compile as mdxCompile} from "@mdx-js/mdx";
|
|
6
|
-
|
|
7
|
-
import {mdxOptions} from "@/mdx/options";
|
|
8
|
-
|
|
9
|
-
export async function compileBySlug(
|
|
10
|
-
slug: string,
|
|
11
|
-
mdx: boolean
|
|
12
|
-
): Promise<string> {
|
|
13
|
-
// TODO: cwd ?
|
|
14
|
-
const filePath = path.join(process.cwd(), `${slug}.${mdx ? "mdx" : "md"}`)
|
|
15
|
-
|
|
16
|
-
await fs.access(filePath)
|
|
17
|
-
|
|
18
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
19
|
-
|
|
20
|
-
return await compile(content, filePath)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function compile(content: string, filePath: string): Promise<string> {
|
|
24
|
-
const vfile = new VFile({
|
|
25
|
-
path: filePath,
|
|
26
|
-
value: content,
|
|
27
|
-
contents: content
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const mdOptions = mdxOptions({
|
|
31
|
-
minDepth: 2 // TODO: configurable?
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const compiled = await mdxCompile(vfile, {
|
|
35
|
-
remarkPlugins: mdOptions.remarkPlugins,
|
|
36
|
-
rehypePlugins: mdOptions.rehypePlugins,
|
|
37
|
-
recmaPlugins: [],
|
|
38
|
-
outputFormat: 'function-body',
|
|
39
|
-
development: false,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return String(compiled)
|
|
43
|
-
}
|
package/vite.config.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {defineConfig} from 'vite';
|
|
2
|
-
|
|
3
|
-
export default defineConfig(async () => {
|
|
4
|
-
const mdx = await import('@mdx-js/rollup');
|
|
5
|
-
const remix = await import('@remix-run/dev');
|
|
6
|
-
const remarkFrontmatter = await import('remark-frontmatter');
|
|
7
|
-
const remarkMdxFrontmatter = await import('remark-mdx-frontmatter');
|
|
8
|
-
const remarkGfm = await import('remark-gfm');
|
|
9
|
-
const rehypePrettyCode = await import('rehype-pretty-code'); // TODO: for some reasons does not work
|
|
10
|
-
// const { remarkCodeHike, recmaCodeHike } = await import('codehike/mdx'); // TODO: delete because we use this inside components?
|
|
11
|
-
|
|
12
|
-
const settings = await import("./settings.json");
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
optimizeDeps: {
|
|
16
|
-
include: ["react/jsx-runtime"],
|
|
17
|
-
},
|
|
18
|
-
resolve: {},
|
|
19
|
-
plugins: [
|
|
20
|
-
mdx.default({
|
|
21
|
-
// providerImportSource: '@mdx-js/react',
|
|
22
|
-
remarkPlugins: [
|
|
23
|
-
// remarkCodeHike,
|
|
24
|
-
remarkFrontmatter.default,
|
|
25
|
-
remarkMdxFrontmatter.default,
|
|
26
|
-
remarkGfm.default
|
|
27
|
-
],
|
|
28
|
-
rehypePlugins: [
|
|
29
|
-
// recmaCodeHike,
|
|
30
|
-
// rehypePrettyCode.default, TODO: for some reasons does not work
|
|
31
|
-
],
|
|
32
|
-
}),
|
|
33
|
-
remix.vitePlugin({
|
|
34
|
-
// routes(defineRoutes) {
|
|
35
|
-
// return defineRoutes((route) => {
|
|
36
|
-
// route(
|
|
37
|
-
// "authentication",
|
|
38
|
-
// "routes/_index.tsx",
|
|
39
|
-
// {id: 'routes/__main-index'},
|
|
40
|
-
// () => {
|
|
41
|
-
// route(
|
|
42
|
-
// "test",
|
|
43
|
-
// "routes/$page.tsx",
|
|
44
|
-
// {id: 'routes/__main-index-2'},
|
|
45
|
-
// );
|
|
46
|
-
// });
|
|
47
|
-
// });
|
|
48
|
-
// },
|
|
49
|
-
}),
|
|
50
|
-
// Add other plugins here
|
|
51
|
-
],
|
|
52
|
-
};
|
|
53
|
-
});
|