@rasenganjs/mdx 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -11
- package/lib/components/codeblock.d.ts +15 -0
- package/lib/components/codeblock.js +63 -0
- package/lib/components/codeblock.js.map +1 -0
- package/lib/components/heading.d.ts +2 -0
- package/lib/components/heading.js +40 -0
- package/lib/components/heading.js.map +1 -0
- package/lib/components/index.d.ts +2 -25
- package/lib/components/index.js +12 -78
- package/lib/components/index.js.map +1 -1
- package/lib/components/table.d.ts +3 -0
- package/lib/components/table.js +5 -0
- package/lib/components/table.js.map +1 -0
- package/lib/index.d.ts +3 -26
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +25 -1
- package/lib/utils/extract-toc.d.ts +1 -0
- package/lib/utils/extract-toc.js +12 -0
- package/lib/utils/extract-toc.js.map +1 -0
- package/lib/utils/index.d.ts +1 -3
- package/lib/utils/index.js +1 -4
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mark-to-html.d.ts +1 -0
- package/lib/utils/mark-to-html.js +15 -0
- package/lib/utils/mark-to-html.js.map +1 -0
- package/lib/utils/plugin.d.ts +2 -2
- package/lib/utils/plugin.js +19 -6
- package/lib/utils/plugin.js.map +1 -1
- package/package.json +59 -52
- package/lib/utils/generate-page.d.ts +0 -10
- package/lib/utils/generate-page.js +0 -18
- package/lib/utils/generate-page.js.map +0 -1
- package/lib/utils/globals.d.ts +0 -20
- package/lib/utils/globals.js +0 -30
- package/lib/utils/globals.js.map +0 -1
- package/lib/utils/polyfills.d.ts +0 -29
- package/lib/utils/polyfills.js +0 -120
- package/lib/utils/polyfills.js.map +0 -1
- package/lib/utils/test.d.ts +0 -1
- package/lib/utils/test.js +0 -6
- package/lib/utils/test.js.map +0 -1
- package/src/components/index.tsx +0 -219
- package/src/index.ts +0 -15
- package/src/types/index.ts +0 -15
- package/src/utils/create-filter.ts +0 -26
- package/src/utils/generate-page.tsx +0 -24
- package/src/utils/globals.ts +0 -32
- package/src/utils/index.ts +0 -6
- package/src/utils/plugin.ts +0 -83
- package/src/utils/polyfills.ts +0 -120
- package/src/utils/test.js +0 -7
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type PageComponent } from "rasengan";
|
|
2
|
-
import { MDXPageComponent } from "../types/index.js";
|
|
3
|
-
import { MDXRenderer } from "../components/index.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generates a React component from an MDXPageComponent.
|
|
7
|
-
*
|
|
8
|
-
* @param MDXPage - The MDXPageComponent to generate the React component from.
|
|
9
|
-
* @param className - An optional CSS class name to apply to the MDXRenderer component.
|
|
10
|
-
* @returns A React component that renders the MDXPage content using the MDXRenderer.
|
|
11
|
-
*/
|
|
12
|
-
export default function generatePage(
|
|
13
|
-
MDXPage: MDXPageComponent,
|
|
14
|
-
className = ""
|
|
15
|
-
): PageComponent {
|
|
16
|
-
const Page: PageComponent = () => {
|
|
17
|
-
return <MDXRenderer className={className}>{MDXPage}</MDXRenderer>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
Page.path = MDXPage.metadata.path;
|
|
21
|
-
Page.metadata = MDXPage.metadata.metadata;
|
|
22
|
-
|
|
23
|
-
return Page;
|
|
24
|
-
}
|
package/src/utils/globals.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import inject from "@rollup/plugin-inject";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Provides a Vite plugin that polyfills the `process` and `Buffer` global variables for the browser.
|
|
5
|
-
* This is necessary for certain libraries that expect these global variables to be available.
|
|
6
|
-
* The plugin is applied during the build phase of the Vite build process.
|
|
7
|
-
*/
|
|
8
|
-
export default function globals() {
|
|
9
|
-
return {
|
|
10
|
-
name: "vite-plugin-rasengan-global-polyfill",
|
|
11
|
-
config: function config(config, env) {
|
|
12
|
-
// test if we are on the browser
|
|
13
|
-
return {
|
|
14
|
-
define: {
|
|
15
|
-
process: process,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
build: {
|
|
19
|
-
rollupOptions: {
|
|
20
|
-
plugins: [
|
|
21
|
-
inject({
|
|
22
|
-
Buffer: ["buffer", "Buffer"],
|
|
23
|
-
}),
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
apply: "build",
|
|
31
|
-
};
|
|
32
|
-
}
|
package/src/utils/index.ts
DELETED
package/src/utils/plugin.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import mdx from '@mdx-js/rollup'
|
|
2
|
-
import matter from 'gray-matter';
|
|
3
|
-
import createFilter from './create-filter.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A Vite plugin that transforms MDX files into a format that can be used in a RasenganJs application.
|
|
7
|
-
*
|
|
8
|
-
* The plugin performs the following tasks:
|
|
9
|
-
* - Resolves the Vite configuration and stores it for later use.
|
|
10
|
-
* - Transforms MDX files by applying the `@mdx-js/rollup` transformation.
|
|
11
|
-
* - Extracts frontmatter data from the MDX files and creates a `metadata` object.
|
|
12
|
-
* - Appends the `metadata` object to the transformed MDX content.
|
|
13
|
-
*
|
|
14
|
-
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
15
|
-
*/
|
|
16
|
-
export default function plugin() {
|
|
17
|
-
let config: unknown;
|
|
18
|
-
const filter = createFilter("**/*.md?(x)");
|
|
19
|
-
const mdxInstance = mdx();
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
name: "vite-plugin-rasengan-mdx",
|
|
23
|
-
|
|
24
|
-
// Apply transformation of the mdx file before other plugins
|
|
25
|
-
enforce: 'pre',
|
|
26
|
-
|
|
27
|
-
config(config: unknown, env: any) {
|
|
28
|
-
mdxInstance.config(config, env);
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Stores the resolved Vite configuration for later use.
|
|
33
|
-
*
|
|
34
|
-
* @param resolvedConfig - The resolved Vite configuration object.
|
|
35
|
-
*/
|
|
36
|
-
configResolved(resolvedConfig: unknown) {
|
|
37
|
-
// store the resolved config
|
|
38
|
-
config = resolvedConfig;
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
43
|
-
*
|
|
44
|
-
* @param code - The content of the MDX file.
|
|
45
|
-
* @param id - The ID of the MDX file.
|
|
46
|
-
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
47
|
-
*/
|
|
48
|
-
async transform(code: string, id: string) {
|
|
49
|
-
if (!filter(id)) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const { content, data: frontmatter } = matter(code);
|
|
54
|
-
|
|
55
|
-
// Apply transformation of the mdx file
|
|
56
|
-
const result = await mdxInstance.transform(content, id);
|
|
57
|
-
|
|
58
|
-
// Extract the file name from the path
|
|
59
|
-
const fileName = id
|
|
60
|
-
.split("/")
|
|
61
|
-
.pop()
|
|
62
|
-
.replace(/.page.mdx?$/, "");
|
|
63
|
-
|
|
64
|
-
// TODO: Consider other params of metadata from frontmatter
|
|
65
|
-
const metadata = {
|
|
66
|
-
path: frontmatter.path || `/${fileName}`,
|
|
67
|
-
metadata: frontmatter.metadata || {
|
|
68
|
-
title: fileName,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
code: `
|
|
74
|
-
${result.code}
|
|
75
|
-
const metadata = ${JSON.stringify(metadata)};
|
|
76
|
-
|
|
77
|
-
MDXContent.metadata = metadata;
|
|
78
|
-
`,
|
|
79
|
-
map: result.map,
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
package/src/utils/polyfills.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Vite plugin that provides polyfills for Node.js modules and APIs when running in a browser environment.
|
|
3
|
-
* This plugin is designed to work with the Vite bundler and helps ensure compatibility with Node.js-based code
|
|
4
|
-
* that is being used in a browser context.
|
|
5
|
-
*
|
|
6
|
-
* The plugin configures Vite's resolver to map various Node.js modules and APIs to their browser-compatible
|
|
7
|
-
* counterparts, allowing the code to run seamlessly in the browser without requiring changes to the original
|
|
8
|
-
* Node.js-based implementation.
|
|
9
|
-
*
|
|
10
|
-
* This plugin is particularly useful when working with libraries or frameworks that rely on Node.js-specific
|
|
11
|
-
* functionality, such as the `process` object or various built-in modules like `fs`, `crypto`, and `http`.
|
|
12
|
-
*/
|
|
13
|
-
export default function polyfill() {
|
|
14
|
-
return {
|
|
15
|
-
name: "vite-plugin-rasengan-node-polyfill",
|
|
16
|
-
config: function config(config, env) {
|
|
17
|
-
// test if we are on the browser
|
|
18
|
-
return {
|
|
19
|
-
define: {
|
|
20
|
-
"process.env": process.env,
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
resolve: {
|
|
24
|
-
alias: [
|
|
25
|
-
// {
|
|
26
|
-
// find: "assert",
|
|
27
|
-
// replacement: "assert",
|
|
28
|
-
// },
|
|
29
|
-
// {
|
|
30
|
-
// find: "buffer",
|
|
31
|
-
// replacement: "buffer/",
|
|
32
|
-
// },
|
|
33
|
-
// {
|
|
34
|
-
// find: "process",
|
|
35
|
-
// replacement: "process/browser.js",
|
|
36
|
-
// },
|
|
37
|
-
// {
|
|
38
|
-
// find: "console",
|
|
39
|
-
// replacement: "console-browserify",
|
|
40
|
-
// },
|
|
41
|
-
{
|
|
42
|
-
find: "fs",
|
|
43
|
-
replacement: "browserify-fs",
|
|
44
|
-
},
|
|
45
|
-
// {
|
|
46
|
-
// find: "crypto",
|
|
47
|
-
// replacement: "crypto-browserify",
|
|
48
|
-
// },
|
|
49
|
-
// {
|
|
50
|
-
// find: "domain",
|
|
51
|
-
// replacement: "domain-browser",
|
|
52
|
-
// },
|
|
53
|
-
// {
|
|
54
|
-
// find: "events",
|
|
55
|
-
// replacement: "events",
|
|
56
|
-
// },
|
|
57
|
-
// {
|
|
58
|
-
// find: "http",
|
|
59
|
-
// replacement: "stream-http",
|
|
60
|
-
// },
|
|
61
|
-
// {
|
|
62
|
-
// find: "https",
|
|
63
|
-
// replacement: "https-browserify",
|
|
64
|
-
// },
|
|
65
|
-
// {
|
|
66
|
-
// find: "path",
|
|
67
|
-
// replacement: "path-browserify",
|
|
68
|
-
// },
|
|
69
|
-
// {
|
|
70
|
-
// find: "punycode",
|
|
71
|
-
// replacement: "punycode",
|
|
72
|
-
// },
|
|
73
|
-
// {
|
|
74
|
-
// find: "querystring",
|
|
75
|
-
// replacement: "querystring-es3",
|
|
76
|
-
// },
|
|
77
|
-
// {
|
|
78
|
-
// find: "stream",
|
|
79
|
-
// replacement: "stream-browserify",
|
|
80
|
-
// },
|
|
81
|
-
// {
|
|
82
|
-
// find: "string_decoder",
|
|
83
|
-
// replacement: "string_decoder",
|
|
84
|
-
// },
|
|
85
|
-
// {
|
|
86
|
-
// find: "sys",
|
|
87
|
-
// replacement: "util",
|
|
88
|
-
// },
|
|
89
|
-
// {
|
|
90
|
-
// find: "timers",
|
|
91
|
-
// replacement: "timers-browserify",
|
|
92
|
-
// },
|
|
93
|
-
// {
|
|
94
|
-
// find: "tty",
|
|
95
|
-
// replacement: "tty-browserify",
|
|
96
|
-
// },
|
|
97
|
-
// {
|
|
98
|
-
// find: "url",
|
|
99
|
-
// replacement: "url",
|
|
100
|
-
// },
|
|
101
|
-
// {
|
|
102
|
-
// find: "util",
|
|
103
|
-
// replacement: "util",
|
|
104
|
-
// },
|
|
105
|
-
// {
|
|
106
|
-
// find: "vm",
|
|
107
|
-
// replacement: "vm-browserify",
|
|
108
|
-
// },
|
|
109
|
-
// {
|
|
110
|
-
// find: "zlib",
|
|
111
|
-
// replacement: "browserify-zlib",
|
|
112
|
-
// },
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
enforce: "pre",
|
|
118
|
-
apply: "build",
|
|
119
|
-
};
|
|
120
|
-
}
|
package/src/utils/test.js
DELETED