@rasenganjs/mdx 1.0.4 → 1.0.6
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 +9 -9
- package/lib/components/codeblock.d.ts +2 -2
- package/lib/components/codeblock.js +16 -17
- package/lib/components/codeblock.js.map +1 -1
- package/lib/components/codeblock2.d.ts +14 -0
- package/lib/components/codeblock2.js +46 -0
- package/lib/components/codeblock2.js.map +1 -0
- package/lib/components/heading.d.ts +1 -1
- package/lib/components/heading.js +12 -12
- package/lib/components/heading.js.map +1 -1
- package/lib/components/index.d.ts +3 -12
- package/lib/components/index.js +5 -25
- package/lib/components/index.js.map +1 -1
- package/lib/components/markdown.d.ts +6 -0
- package/lib/components/markdown.js +29 -0
- package/lib/components/markdown.js.map +1 -0
- package/lib/components/renderer.d.ts +12 -0
- package/lib/components/renderer.js +26 -0
- package/lib/components/renderer.js.map +1 -0
- package/lib/components/table.d.ts +2 -2
- package/lib/components/table.js +1 -1
- package/lib/components/table.js.map +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/styles/rasengan-mdx.min.css +1 -1
- package/lib/types/index.d.ts +8 -2
- package/lib/utils/create-filter.js +1 -1
- package/lib/utils/create-filter.js.map +1 -1
- package/lib/utils/extract-toc.js +3 -3
- package/lib/utils/extract-toc.js.map +1 -1
- package/lib/utils/generate-navigation.d.ts +0 -0
- package/lib/utils/generate-navigation.js +75 -0
- package/lib/utils/generate-navigation.js.map +1 -0
- package/lib/utils/index.d.ts +19 -1
- package/lib/utils/index.js +4 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mark-to-html.js +5 -5
- package/lib/utils/mark-to-html.js.map +1 -1
- package/lib/utils/plugin.d.ts +1 -13
- package/lib/utils/plugin.js +13 -17
- package/lib/utils/plugin.js.map +1 -1
- package/lib/utils/polyfill.d.ts +10 -0
- package/lib/utils/polyfill.js +15 -0
- package/lib/utils/polyfill.js.map +1 -0
- package/package.json +69 -64
- package/tsconfig.json +2 -12
package/README.md
CHANGED
|
@@ -31,8 +31,8 @@ Here is an example of how you can use the `@rasenganjs/mdx` package:
|
|
|
31
31
|
Import the `mdx` plugin into the `rasengan.config.js` file.
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
import { defineConfig } from
|
|
35
|
-
import mdx from
|
|
34
|
+
import { defineConfig } from 'rasengan';
|
|
35
|
+
import mdx from '@rasenganjs/mdx';
|
|
36
36
|
|
|
37
37
|
export default defineConfig({
|
|
38
38
|
vite: {
|
|
@@ -53,7 +53,7 @@ metadata:
|
|
|
53
53
|
description: Discover our new blog posts
|
|
54
54
|
---
|
|
55
55
|
|
|
56
|
-
import Button from
|
|
56
|
+
import Button from '@/components/Button';
|
|
57
57
|
|
|
58
58
|
# Blog page
|
|
59
59
|
|
|
@@ -67,10 +67,10 @@ This is a `blog` page.
|
|
|
67
67
|
Inside the `app.router.ts` file, import your Markdown Component and the `MDXRenderer` component from `@rasenganjs/mdx` and add it to `defineRouter` option like this:
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
|
-
import { RouterComponent, defineRouter } from
|
|
71
|
-
import AppLayout from
|
|
72
|
-
import Blog from
|
|
73
|
-
import { MDXRenderer } from
|
|
70
|
+
import { RouterComponent, defineRouter } from 'rasengan';
|
|
71
|
+
import AppLayout from '@app/app.layout';
|
|
72
|
+
import Blog from '@app/blog.page.mdx';
|
|
73
|
+
import { MDXRenderer } from '@rasenganjs/mdx';
|
|
74
74
|
|
|
75
75
|
class AppRouter extends RouterComponent {}
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@ export default defineRouter({
|
|
|
78
78
|
imports: [],
|
|
79
79
|
layout: AppLayout,
|
|
80
80
|
pages: [Blog],
|
|
81
|
-
MDXRenderer
|
|
81
|
+
MDXRenderer,
|
|
82
82
|
})(AppRouter);
|
|
83
83
|
```
|
|
84
84
|
|
|
@@ -112,4 +112,4 @@ We also have a [Twitter](https://twitter.com/rasenganjs) account where you can f
|
|
|
112
112
|
|
|
113
113
|
Here is the authors list:
|
|
114
114
|
|
|
115
|
-
- Dilane Kombou ([**@dilanekombou**](https://twitter.com/dilanekombou))
|
|
115
|
+
- Dilane Kombou ([**@dilanekombou**](https://twitter.com/dilanekombou))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { CodeBlockProps, ComponentWithTextChildrenProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CodeBlockProps, ComponentWithTextChildrenProps } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
5
5
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React from
|
|
3
|
-
import { renderToString } from
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { renderToString } from 'react-dom/server';
|
|
4
4
|
/**
|
|
5
5
|
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
6
6
|
*
|
|
@@ -12,10 +12,9 @@ import { renderToString } from "react-dom/server";
|
|
|
12
12
|
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
13
13
|
* @returns {React.ReactElement} - The rendered code block component.
|
|
14
14
|
*/
|
|
15
|
-
export const CodeBlock = ({ children, className =
|
|
16
|
-
const language = rest[
|
|
17
|
-
const numbers = rest[
|
|
18
|
-
// const theme = rest["data-theme"] || "github-dark-dimmed";
|
|
15
|
+
export const CodeBlock = ({ children, className = '', ...rest }) => {
|
|
16
|
+
const language = rest['data-language'] || '';
|
|
17
|
+
const numbers = rest['data-line-numbers'];
|
|
19
18
|
const [hover, setHover] = React.useState(false);
|
|
20
19
|
const [copied, setCopied] = React.useState(false);
|
|
21
20
|
React.useEffect(() => {
|
|
@@ -40,24 +39,24 @@ export const CodeBlock = ({ children, className = "", ...rest }) => {
|
|
|
40
39
|
setCopied(true);
|
|
41
40
|
};
|
|
42
41
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
* Extracts the text content from an HTML string.
|
|
43
|
+
*
|
|
44
|
+
* This function takes an HTML string as input and returns the plain text content of the HTML, excluding any HTML tags or markup.
|
|
45
|
+
*
|
|
46
|
+
* @param htmlString - The HTML string to extract text from.
|
|
47
|
+
* @returns The plain text content of the HTML string.
|
|
48
|
+
*/
|
|
50
49
|
const extractTextFromHTML = (htmlString) => {
|
|
51
50
|
const parser = new DOMParser();
|
|
52
|
-
const doc = parser.parseFromString(htmlString,
|
|
53
|
-
return doc.body.textContent ||
|
|
51
|
+
const doc = parser.parseFromString(htmlString, 'text/html');
|
|
52
|
+
return doc.body.textContent || '';
|
|
54
53
|
};
|
|
55
54
|
if (!language) {
|
|
56
55
|
return _jsx(SimpleBlock, { children: children });
|
|
57
56
|
}
|
|
58
|
-
return (_jsxs("div", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [hover ? (_jsx("button", { className:
|
|
57
|
+
return (_jsxs("div", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [hover ? (_jsx("button", { className: "copy-button", onClick: handleCopy, children: copied ? (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "16", height: "16", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z", stroke: "currentColor", strokeWidth: "1.5" }), _jsx("path", { d: "M8 12.5L10.5 15L16 9", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) : (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "16", height: "16", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) })) : (_jsx("span", { className: "lang", children: language })), _jsx("code", { className: `${className} code-block`, "data-line-numbers": numbers !== undefined ? '' : undefined, children: children })] }));
|
|
59
58
|
};
|
|
60
59
|
export const SimpleBlock = ({ children, }) => {
|
|
61
|
-
return _jsx("code", { className:
|
|
60
|
+
return _jsx("code", { className: "simple-block", children: children });
|
|
62
61
|
};
|
|
63
62
|
//# sourceMappingURL=codeblock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeblock.js","sourceRoot":"","sources":["../../src/components/codeblock.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"codeblock.js","sourceRoot":"","sources":["../../src/components/codeblock.tsx"],"names":[],"mappings":";AAAA,OAAO,KAA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B,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,IACE,CACP,GACM,CACV,CAAC,CAAC,CAAC,CACF,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,CACzC,EACD,eACE,SAAS,EAAE,GAAG,SAAS,aAAa,uBACjB,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YAExD,QAAQ,GACJ,IACH,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,QAAQ,GACuB,EAAsB,EAAE;IACvD,OAAO,eAAM,SAAS,EAAC,cAAc,YAAE,QAAQ,GAAQ,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CodeBlockProps } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
5
|
+
*
|
|
6
|
+
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
7
|
+
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} props - The component props.
|
|
10
|
+
* @param {string} props.children - The code content to be displayed in the code block.
|
|
11
|
+
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
12
|
+
* @returns {React.ReactElement} - The rendered code block component.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CodeBlock2: ({ children, className, }: CodeBlockProps) => React.ReactElement;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { themes, Highlight } from 'prism-react-renderer';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { SimpleBlock } from './codeblock.js';
|
|
5
|
+
/**
|
|
6
|
+
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
7
|
+
*
|
|
8
|
+
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
9
|
+
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} props - The component props.
|
|
12
|
+
* @param {string} props.children - The code content to be displayed in the code block.
|
|
13
|
+
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
14
|
+
* @returns {React.ReactElement} - The rendered code block component.
|
|
15
|
+
*/
|
|
16
|
+
export const CodeBlock2 = ({ children, className = '', }) => {
|
|
17
|
+
const language = className.replace(/language-/, '');
|
|
18
|
+
const [hover, setHover] = React.useState(false);
|
|
19
|
+
if (!language) {
|
|
20
|
+
return _jsx(SimpleBlock, { children: children });
|
|
21
|
+
}
|
|
22
|
+
return (_jsx(Highlight, { theme: themes.oneDark, code: children.trim(), language: language, children: ({ className, tokens, getLineProps, getTokenProps, ...rest }) => {
|
|
23
|
+
const [copied, setCopied] = React.useState(false);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
/**
|
|
26
|
+
* Sets the `copied` state to `false` after 2 seconds, effectively hiding the "copied" indicator.
|
|
27
|
+
* This function is called after the user's clipboard is updated with the code content.
|
|
28
|
+
*/
|
|
29
|
+
const timer = setTimeout(() => {
|
|
30
|
+
setCopied(false);
|
|
31
|
+
}, 2000);
|
|
32
|
+
return () => clearTimeout(timer);
|
|
33
|
+
}, [copied]);
|
|
34
|
+
/**
|
|
35
|
+
* Copies the trimmed text content of the `children` prop to the user's clipboard.
|
|
36
|
+
* This function is called when the "Copy" button is clicked in the code block component.
|
|
37
|
+
* It sets the `copied` state to `true` for 2 seconds to display a "copied" indicator.
|
|
38
|
+
*/
|
|
39
|
+
const handleCopy = () => {
|
|
40
|
+
navigator.clipboard.writeText((children ?? '').trim());
|
|
41
|
+
setCopied(true);
|
|
42
|
+
};
|
|
43
|
+
return (_jsx("figure", { children: _jsx("pre", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), "data-language": language, children: _jsxs("div", { children: [hover ? (_jsx("button", { className: "copy-button", onClick: handleCopy, children: copied ? (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "20", height: "20", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z", stroke: "currentColor", strokeWidth: "1.5" }), _jsx("path", { d: "M8 12.5L10.5 15L16 9", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) : (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "20", height: "20", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) })) : (_jsx("span", { className: "lang", children: language })), _jsx("code", { className: `${className} code-block`, "data-line-numbers": true, children: tokens.map((line, i) => (_jsxs("span", { "data-line": true, ...getLineProps({ line }), children: [_jsx("span", { children: " " }), line.map((token, key) => (_jsx("span", { ...getTokenProps({ token }) }, key)))] }, i))) })] }) }) }));
|
|
44
|
+
} }));
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=codeblock2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeblock2.js","sourceRoot":"","sources":["../../src/components/codeblock2.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,QAAQ,EACR,SAAS,GAAG,EAAE,GACC,EAAsB,EAAE;IACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEhD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAC,WAAW,cAAE,QAAQ,GAAe,CAAC;IAC/C,CAAC;IAED,OAAO,CACL,KAAC,SAAS,IACR,KAAK,EAAE,MAAM,CAAC,OAAO,EACrB,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EACrB,QAAQ,EAAE,QAAQ,YAEjB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,IAAI,EAAO,EAAE,EAAE;YACpE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAElD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;gBACnB;;;mBAGG;gBACH,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;oBAC5B,SAAS,CAAC,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MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,EACF,eACE,CAAC,EAAC,gXAAgX,EAClX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,IACE,CACP,GACM,CACV,CAAC,CAAC,CAAC,CACF,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,CACzC,EAED,eAAM,SAAS,EAAE,GAAG,SAAS,aAAa,uCACvC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CACpC,sCAA4B,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,aAChD,+BAAc,EACb,IAAI,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,GAAW,EAAE,EAAE,CAAC,CACrC,kBAAoB,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,IAAjC,GAAG,CAAkC,CACjD,CAAC,KAJiB,CAAC,CAKf,CACR,CAAC,GACG,IACH,GACF,GACC,CACV,CAAC;QACJ,CAAC,GACS,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { HeadingProps, HeadingProps2 } from
|
|
1
|
+
import { HeadingProps, HeadingProps2 } from '../types/index.js';
|
|
2
2
|
export declare const Heading: ({ variant }: HeadingProps) => ({ children }: HeadingProps2) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createElement, useMemo } from
|
|
2
|
+
import { createElement, useMemo } from 'react';
|
|
3
3
|
export const Heading = ({ variant }) => {
|
|
4
4
|
return ({ children }) => {
|
|
5
5
|
const { text, id } = useMemo(() => {
|
|
6
6
|
// Regex pattern to match links in the format [#link text]
|
|
7
|
-
const regex = new RegExp(
|
|
7
|
+
const regex = new RegExp('^\\[#.+\\]');
|
|
8
8
|
// split the children into an array of strings based on space
|
|
9
|
-
const childrenArray = children.split(
|
|
10
|
-
let lastWord =
|
|
11
|
-
let restOfTheWords =
|
|
12
|
-
let link =
|
|
9
|
+
const childrenArray = children.split(' [#');
|
|
10
|
+
let lastWord = '';
|
|
11
|
+
let restOfTheWords = '';
|
|
12
|
+
let link = '';
|
|
13
13
|
// Check if we have more than one word and if the last word is a link
|
|
14
14
|
if (childrenArray.length > 1 &&
|
|
15
|
-
childrenArray.at(-1).includes(
|
|
15
|
+
childrenArray.at(-1).includes(']') &&
|
|
16
16
|
regex.test(`[#${childrenArray.at(-1)}`)) {
|
|
17
17
|
lastWord = childrenArray.pop();
|
|
18
18
|
}
|
|
19
19
|
if (lastWord) {
|
|
20
|
-
link = lastWord.replace(
|
|
20
|
+
link = lastWord.replace(']', '').split(' ').join('-').toLowerCase();
|
|
21
21
|
restOfTheWords = childrenArray[0];
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
link = children.split(
|
|
24
|
+
link = children.split(' ').join('-').toLowerCase();
|
|
25
25
|
restOfTheWords = children;
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
28
|
-
id: variant ===
|
|
28
|
+
id: variant === 'h1' ? undefined : link,
|
|
29
29
|
text: restOfTheWords,
|
|
30
30
|
};
|
|
31
31
|
}, [children]);
|
|
32
32
|
const heading = createElement(variant, {
|
|
33
33
|
id,
|
|
34
|
-
className:
|
|
34
|
+
className: 'heading',
|
|
35
35
|
children: text,
|
|
36
36
|
});
|
|
37
|
-
return (_jsxs("div", { className:
|
|
37
|
+
return (_jsxs("div", { className: "ra-heading-wrapper", children: [heading, id && (_jsx("a", { href: `#${id}`, children: _jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", color: "#ffffff", fill: "none", children: [_jsx("path", { d: "M10 13.229C10.1416 13.4609 10.3097 13.6804 10.5042 13.8828C11.7117 15.1395 13.5522 15.336 14.9576 14.4722C15.218 14.3121 15.4634 14.1157 15.6872 13.8828L18.9266 10.5114C20.3578 9.02184 20.3578 6.60676 18.9266 5.11718C17.4953 3.6276 15.1748 3.62761 13.7435 5.11718L13.03 5.85978", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }), _jsx("path", { d: "M10.9703 18.14L10.2565 18.8828C8.82526 20.3724 6.50471 20.3724 5.07345 18.8828C3.64218 17.3932 3.64218 14.9782 5.07345 13.4886L8.31287 10.1172C9.74413 8.62761 12.0647 8.6276 13.4959 10.1172C13.6904 10.3195 13.8584 10.539 14 10.7708", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })] }) }))] }));
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
//# sourceMappingURL=heading.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading.js","sourceRoot":"","sources":["../../src/components/heading.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,OAAO,EAAgB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"heading.js","sourceRoot":"","sources":["../../src/components/heading.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,OAAO,EAAgB,EAAE,EAAE;IACnD,OAAO,CAAC,EAAE,QAAQ,EAAiB,EAAE,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;YAChC,0DAA0D;YAC1D,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;YAEvC,6DAA6D;YAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,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AAI,EAAE,EAAE,YACf,eACE,KAAK,EAAC,4BAA4B,EAClC,OAAO,EAAC,WAAW,EACnB,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,KAAK,EAAC,SAAS,EACf,IAAI,EAAC,MAAM,aAEX,eACE,CAAC,EAAC,uRAAuR,EACzR,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACrB,EACF,eACE,CAAC,EAAC,yOAAyO,EAC3O,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACrB,IACE,GACJ,CACL,IACG,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
* Renders an MDX content component with a custom code block component.
|
|
5
|
-
*
|
|
6
|
-
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
7
|
-
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
8
|
-
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
9
|
-
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
10
|
-
*/
|
|
11
|
-
declare const MDXRenderer: ({ children: MDXContent, className }: MDXRendererProps) => React.ReactElement;
|
|
12
|
-
export { MDXRenderer };
|
|
1
|
+
import { MDXRenderer } from './renderer.js';
|
|
2
|
+
import { Markdown } from './markdown.js';
|
|
3
|
+
export { Markdown, MDXRenderer };
|
package/lib/components/index.js
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Renders an MDX content component with a custom code block component.
|
|
7
|
-
*
|
|
8
|
-
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
9
|
-
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
10
|
-
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
11
|
-
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
12
|
-
*/
|
|
13
|
-
const MDXRenderer = ({ children: MDXContent, className }) => {
|
|
14
|
-
return (_jsx("section", { className: "rasengan-markdown-body " + className, children: _jsx(MDXContent, { components: {
|
|
15
|
-
code: CodeBlock,
|
|
16
|
-
table: Table,
|
|
17
|
-
h1: Heading({ variant: "h1" }),
|
|
18
|
-
h2: Heading({ variant: "h2" }),
|
|
19
|
-
h3: Heading({ variant: "h3" }),
|
|
20
|
-
h4: Heading({ variant: "h4" }),
|
|
21
|
-
h5: Heading({ variant: "h5" }),
|
|
22
|
-
h6: Heading({ variant: "h6" }),
|
|
23
|
-
} }) }));
|
|
24
|
-
};
|
|
25
|
-
export { MDXRenderer };
|
|
1
|
+
// Import statements
|
|
2
|
+
import { MDXRenderer } from './renderer.js';
|
|
3
|
+
import { Markdown } from './markdown.js';
|
|
4
|
+
// Export statements
|
|
5
|
+
export { Markdown, MDXRenderer };
|
|
26
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,oBAAoB;AACpB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Table } from './table.js';
|
|
3
|
+
import { Heading } from './heading.js';
|
|
4
|
+
import MarkdownComponent from 'react-markdown';
|
|
5
|
+
import remarkGfm from 'remark-gfm';
|
|
6
|
+
import rehypeStringify from 'rehype-stringify';
|
|
7
|
+
import remarkParse from 'remark-parse';
|
|
8
|
+
import remarkRehype from 'remark-rehype';
|
|
9
|
+
// import rehypePrettyCode from "rehype-pretty-code";
|
|
10
|
+
import { CodeBlock2 } from './codeblock2.js';
|
|
11
|
+
function Markdown({ content, className, }) {
|
|
12
|
+
return (_jsx("section", { className: 'rasengan-markdown-body ' + className, children: _jsx(MarkdownComponent, { children: content, remarkPlugins: [remarkParse, remarkGfm], rehypePlugins: [
|
|
13
|
+
remarkRehype,
|
|
14
|
+
rehypeStringify,
|
|
15
|
+
// [rehypePrettyCode, {
|
|
16
|
+
// }]
|
|
17
|
+
], components: {
|
|
18
|
+
code: CodeBlock2,
|
|
19
|
+
table: Table,
|
|
20
|
+
h1: Heading({ variant: 'h1' }),
|
|
21
|
+
h2: Heading({ variant: 'h2' }),
|
|
22
|
+
h3: Heading({ variant: 'h3' }),
|
|
23
|
+
h4: Heading({ variant: 'h4' }),
|
|
24
|
+
h5: Heading({ variant: 'h5' }),
|
|
25
|
+
h6: Heading({ variant: 'h6' }),
|
|
26
|
+
} }) }));
|
|
27
|
+
}
|
|
28
|
+
export { Markdown };
|
|
29
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/components/markdown.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,iBAAiB,MAAM,gBAAgB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,qDAAqD;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,SAAS,QAAQ,CAAC,EAChB,OAAO,EACP,SAAS,GAIV;IACC,OAAO,CACL,kBAAS,SAAS,EAAE,yBAAyB,GAAG,SAAS,YACvD,KAAC,iBAAiB,IAChB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,EACvC,aAAa,EAAE;gBACb,YAAY;gBACZ,eAAe;gBACf,uBAAuB;gBAEvB,KAAK;aACN,EACD,UAAU,EAAE;gBACV,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,KAAK;gBACZ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;aAC/B,GACD,GACM,CACX,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MDXRendererProps } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders an MDX content component with a custom code block component.
|
|
5
|
+
*
|
|
6
|
+
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
7
|
+
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
8
|
+
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
9
|
+
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
10
|
+
*/
|
|
11
|
+
declare const MDXRenderer: ({ children: MDXContent, className, }: MDXRendererProps) => React.ReactElement;
|
|
12
|
+
export { MDXRenderer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CodeBlock } from './codeblock.js';
|
|
3
|
+
import { Table } from './table.js';
|
|
4
|
+
import { Heading } from './heading.js';
|
|
5
|
+
/**
|
|
6
|
+
* Renders an MDX content component with a custom code block component.
|
|
7
|
+
*
|
|
8
|
+
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
9
|
+
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
10
|
+
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
11
|
+
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
12
|
+
*/
|
|
13
|
+
const MDXRenderer = ({ children: MDXContent, className, }) => {
|
|
14
|
+
return (_jsx("section", { className: 'rasengan-markdown-body ' + className, children: _jsx(MDXContent, { components: {
|
|
15
|
+
code: CodeBlock,
|
|
16
|
+
table: Table,
|
|
17
|
+
h1: Heading({ variant: 'h1' }),
|
|
18
|
+
h2: Heading({ variant: 'h2' }),
|
|
19
|
+
h3: Heading({ variant: 'h3' }),
|
|
20
|
+
h4: Heading({ variant: 'h4' }),
|
|
21
|
+
h5: Heading({ variant: 'h5' }),
|
|
22
|
+
h6: Heading({ variant: 'h6' }),
|
|
23
|
+
} }) }));
|
|
24
|
+
};
|
|
25
|
+
export { MDXRenderer };
|
|
26
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/components/renderer.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG,CAAC,EACnB,QAAQ,EAAE,UAAU,EACpB,SAAS,GACQ,EAAsB,EAAE;IACzC,OAAO,CACL,kBAAS,SAAS,EAAE,yBAAyB,GAAG,SAAS,YACvD,KAAC,UAAU,IACT,UAAU,EAAE;gBACV,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,KAAK;gBACZ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;aAC/B,GACD,GACM,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { ComponentWithTextChildrenProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentWithTextChildrenProps } from '../types/index.js';
|
|
3
3
|
export declare const Table: ({ children, }: ComponentWithTextChildrenProps) => React.ReactElement;
|
package/lib/components/table.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
export const Table = ({ children, }) => {
|
|
3
|
-
return (_jsx("div", { className:
|
|
3
|
+
return (_jsx("div", { className: "ra-table-wrapper", children: _jsx("table", { children: children }) }));
|
|
4
4
|
};
|
|
5
5
|
//# sourceMappingURL=table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/components/table.tsx"],"names":[],"mappings":";AAGA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/components/table.tsx"],"names":[],"mappings":";AAGA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EACpB,QAAQ,GACuB,EAAsB,EAAE;IACvD,OAAO,CACL,cAAK,SAAS,EAAC,kBAAkB,YAC/B,0BAAQ,QAAQ,GAAS,GACrB,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
7
7
|
*/
|
|
8
|
+
// Export statements
|
|
8
9
|
export * from './types/index.js';
|
|
9
10
|
export * from './components/index.js';
|
|
10
|
-
import { plugin } from "./utils/index.js";
|
|
11
|
-
export default plugin;
|
|
12
11
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oBAAoB;AACpB,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
:root{--bg:transparent;--bg-light:#f5f5f5;--bg-code:#282c34;--bg-code-highlight:#30313e;--bg-code-highlight-2:#494c54;--fg:#333;--fg-code:#adbac7;--fg-light:#666;--fg-dark:#000;--fg-accent:#007bff;--border:#eee;--border-dark:#494c54;--table-border:#d1d5dc}.dark{--bg:#212121;--bg-light:#30313e55;--bg-code:#282c34;--bg-code-highlight:#30313e;--fg:#eee;--fg-code:#abb2bf;--fg-light:#ccc;--fg-dark:#fff;--fg-accent:#007bff;--border:#2f2f2f;--border-dark:#494c54;--table-border:#4b5563}.rasengan-markdown-body{box-sizing:border-box;margin:0;padding:0;font-weight:400}.rasengan-markdown-body .ra-heading-wrapper{display:flex;align-items:center;justify-content:start}.rasengan-markdown-body .ra-heading-wrapper:has(h2){border-bottom:1px solid var(--border);margin:2rem 0}.rasengan-markdown-body .ra-heading-wrapper a{margin:.67em 0;margin-left:.5em;color:var(--border);opacity:0;transition:all .3s}.rasengan-markdown-body .ra-heading-wrapper a>svg{color:var(--fg)}.rasengan-markdown-body .ra-heading-wrapper a:hover>svg{color:var(--fg-accent)}.rasengan-markdown-body .ra-heading-wrapper:has(h2) a{font-size:2em;text-decoration:none}.rasengan-markdown-body .ra-heading-wrapper:has(h3) a{font-size:1.5em;text-decoration:none}.rasengan-markdown-body .ra-heading-wrapper:has(h4) a{font-size:1em;text-decoration:none}.rasengan-markdown-body .ra-heading-wrapper:hover a{opacity:1;cursor:pointer}.rasengan-markdown-body .ra-heading-wrapper:hover a:hover{transform:scale(1.1)}.rasengan-markdown-body h1{font-size:2.5em;color:var(--fg);font-weight:700;margin:1em 0}.rasengan-markdown-body h2{font-size:2em;color:var(--fg);font-weight:700}.rasengan-markdown-body h3{font-size:1.5em;color:var(--fg);font-weight:700}.rasengan-markdown-body h4{font-size:1.17em;color:var(--fg);font-weight:700}.rasengan-markdown-body h5{font-size:1em;color:var(--fg);font-weight:700;margin:.67em 0}.rasengan-markdown-body h6{font-size:.83em;color:var(--fg);font-weight:700;margin:.67em 0}.rasengan-markdown-body h2:hover::after,.rasengan-markdown-body h3:hover::after,.rasengan-markdown-body h4:hover::after{opacity:1;cursor:pointer}.rasengan-markdown-body p{font-size:1em;color:var(--fg);margin:1em 0}.rasengan-markdown-body a{color:var(--fg-accent);text-decoration:none}.rasengan-markdown-body a:hover{text-decoration:underline}.rasengan-markdown-body hr{color:var(--border);margin:1em 0}.rasengan-markdown-body code.simple-block{font-size:.8em;font-family:'JetBrains Mono',monospace;border-radius:5px;padding:2px 3.6px;margin:auto 0;background-color:var(--bg-light);border:1px solid var(--border)}.rasengan-markdown-body figure:has(pre[data-language]){background-color:var(--bg-code);border-radius:8px;margin:10px 0;color:var(--fg-code);border:1px solid var(--border);overflow:hidden}.rasengan-markdown-body figure:has(pre[data-language]) figcaption{padding:10px 20px;font-size:14px;font-weight:400;background-color:var(--bg-code-highlight);border-bottom:1px solid var(--border-dark)}.rasengan-markdown-body code[data-line-numbers]{counter-reset:line}.rasengan-markdown-body pre[data-language]{position:relative;border-radius:8px;border:none;margin:0}.rasengan-markdown-body pre[data-language] code{font-family:'JetBrains Mono',monospace;font-size:14px;overflow-x:auto}.rasengan-markdown-body pre[data-language]>div code{display:grid;grid-template-columns:1fr;line-height:1.6;word-wrap:break-word;padding:16px 0}.rasengan-markdown-body pre[data-language] code>span{padding:0 16px;border-left:4px solid transparent}.rasengan-markdown-body pre[data-language] code[data-line-numbers]>span{padding:0 5px}.rasengan-markdown-body pre[data-language] mark[data-highlighted-chars]{background-color:var(--bg-code-highlight-2);border-radius:5px;padding:0 5px}.rasengan-markdown-body pre[data-language] span[data-highlighted-line]{background-color:var(--bg-code-highlight);border-left:4px solid var(--fg-accent)}.rasengan-markdown-body code[data-line-numbers] span[data-line]:before{counter-increment:line;content:counter(line);display:inline-block;width:2ch;color:#6a737d;text-align:right;margin-right:16px;opacity:.9}.rasengan-markdown-body code.code-block{position:relative;display:block;padding:20px 0;font-size:14px;max-height:800px;overflow:auto}.rasengan-markdown-body pre[data-language] button,.rasengan-markdown-body pre[data-language] span.lang{position:absolute;top:15px;right:15px;transition:all .2s;z-index:10}.rasengan-markdown-body pre[data-language] span.lang{font-size:12px;opacity:.8;color:var(--fg-code);padding:2px 5px;border-radius:5px;background-color:var(--bg-code-highlight);border:1px solid var(--border-dark)}.rasengan-markdown-body pre[data-language] code{font-family:'JetBrains Mono',monospace}.rasengan-markdown-body pre[data-language] button{opacity:.6;cursor:pointer;width:24px;height:24px;border-radius:5px;border:1px solid var(--border-dark);background-color:var(--bg-code-highlight);display:flex;align-items:center;justify-content:center}.rasengan-markdown-body pre[data-language]:hover>div button:hover{opacity:1}.rasengan-markdown-body .ra-table-wrapper{overflow-x:auto}.rasengan-markdown-body table{border-collapse:collapse;color:var(--fg);margin:.67em 0;width:100%;min-width:600px;overflow-x:auto}.rasengan-markdown-body th{background-color:transparent;color:var(--fg);font-weight:700}.rasengan-markdown-body td,.rasengan-markdown-body th{padding:10px 20px;border:1px solid var(--border);transition:all .3s;cursor:pointer}.rasengan-markdown-body tr:nth-child(2n){background-color:var(--bg-light)}.rasengan-markdown-body tr:nth-child(odd){background-color:transparent}.rasengan-markdown-body tr:hover{background-color:var(--bg-light)}.rasengan-markdown-body ol,.rasengan-markdown-body ul{margin:.67em 0;color:var(--fg);padding-left:15px}.rasengan-markdown-body ul{list-style:disc}.rasengan-markdown-body ul:has(li > input){list-style:none}.rasengan-markdown-body ol li,.rasengan-markdown-body ul li{margin:.67em 0;color:var(--fg)}.rasengan-markdown-body ol li input,.rasengan-markdown-body ul li input{margin-right:.3em}.rasengan-markdown-body ol li input:checked,.rasengan-markdown-body ul li input{background-color:var(--fg-accent);color:var(--bg)}.rasengan-markdown-body blockquote{border-left:4px solid var(--border);padding-left:1em;margin:1em 0}.rasengan-markdown-body blockquote p{margin:0}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Metadata } from
|
|
1
|
+
import { type Metadata } from 'rasengan';
|
|
2
2
|
/**
|
|
3
3
|
* A React functional component that represents an MDX page.
|
|
4
4
|
*
|
|
@@ -32,8 +32,14 @@ export type CodeBlockProps = ComponentWithTextChildrenProps & {
|
|
|
32
32
|
className?: string;
|
|
33
33
|
};
|
|
34
34
|
export type HeadingProps = {
|
|
35
|
-
variant:
|
|
35
|
+
variant: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
36
36
|
};
|
|
37
37
|
export type HeadingProps2 = ComponentWithTextChildrenProps & {
|
|
38
38
|
className?: string;
|
|
39
39
|
};
|
|
40
|
+
export type NavigationStructure = {
|
|
41
|
+
title: string;
|
|
42
|
+
link: string;
|
|
43
|
+
level: number;
|
|
44
|
+
children?: NavigationStructure[];
|
|
45
|
+
};
|
|
@@ -8,7 +8,7 @@ import micromatch from 'micromatch';
|
|
|
8
8
|
*/
|
|
9
9
|
export default function createFilter(include, exclude) {
|
|
10
10
|
return function (id) {
|
|
11
|
-
if (typeof id !==
|
|
11
|
+
if (typeof id !== 'string')
|
|
12
12
|
return false;
|
|
13
13
|
const matcher = micromatch.matcher(include);
|
|
14
14
|
if (exclude) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-filter.js","sourceRoot":"","sources":["../../src/utils/create-filter.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,
|
|
1
|
+
{"version":3,"file":"create-filter.js","sourceRoot":"","sources":["../../src/utils/create-filter.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,OAAe,EAAE,OAAgB;IACpE,OAAO,UAAU,EAAU;QACzB,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAEzC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE5C,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/utils/extract-toc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { remark } from
|
|
2
|
-
import remarkToc from
|
|
1
|
+
import { remark } from 'remark';
|
|
2
|
+
import remarkToc from 'remark-toc';
|
|
3
3
|
export async function extractToc(markdown) {
|
|
4
4
|
const file = await remark()
|
|
5
5
|
.use(remarkToc, {
|
|
6
|
-
heading:
|
|
6
|
+
heading: 'structure',
|
|
7
7
|
maxDepth: 3,
|
|
8
8
|
})
|
|
9
9
|
.process(markdown);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-toc.js","sourceRoot":"","sources":["../../src/utils/extract-toc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;
|
|
1
|
+
{"version":3,"file":"extract-toc.js","sourceRoot":"","sources":["../../src/utils/extract-toc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IAC/C,MAAM,IAAI,GAAG,MAAM,MAAM,EAAE;SACxB,GAAG,CAAC,SAAS,EAAE;QACd,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,CAAC;KACZ,CAAC;SACD,OAAO,CAAC,QAAQ,CAAC,CAAC;IAErB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// // @ts-ignore
|
|
2
|
+
// import { RouterComponent } from 'rasengan';
|
|
3
|
+
// import { NavigationStructure } from '../types/index.js';
|
|
4
|
+
// export const generateNavigation = (router: RouterComponent) => {
|
|
5
|
+
// const navigation: NavigationStructure[] = [];
|
|
6
|
+
// const { routers: subRouters, pages } = router;
|
|
7
|
+
// for (const page of pages) {
|
|
8
|
+
// // if (page.metadata?.hidden) {
|
|
9
|
+
// // continue;
|
|
10
|
+
// // }
|
|
11
|
+
// const { exists, isParent, route } = checkIfRouteExists(
|
|
12
|
+
// navigation,
|
|
13
|
+
// page.path
|
|
14
|
+
// );
|
|
15
|
+
// if (exists) {
|
|
16
|
+
// continue;
|
|
17
|
+
// }
|
|
18
|
+
// if (isParent) {
|
|
19
|
+
// route.children.push({
|
|
20
|
+
// title: page.metadata.title,
|
|
21
|
+
// link: page.path,
|
|
22
|
+
// level: route.level + 1,
|
|
23
|
+
// });
|
|
24
|
+
// continue;
|
|
25
|
+
// }
|
|
26
|
+
// navigation.push({
|
|
27
|
+
// title: page.metadata.title,
|
|
28
|
+
// link: page.path,
|
|
29
|
+
// level: 1,
|
|
30
|
+
// children: [],
|
|
31
|
+
// });
|
|
32
|
+
// }
|
|
33
|
+
// // for (const subRouter of subRouters) {
|
|
34
|
+
// // navigation.push({
|
|
35
|
+
// // title: subRouter.layout.title,
|
|
36
|
+
// // link: subRouter.layout.path,
|
|
37
|
+
// // level: 1,
|
|
38
|
+
// // children: generateNavigation(subRouter),
|
|
39
|
+
// // });
|
|
40
|
+
// // }
|
|
41
|
+
// return navigation;
|
|
42
|
+
// };
|
|
43
|
+
// const checkIfRouteExists = (
|
|
44
|
+
// navigation: NavigationStructure[],
|
|
45
|
+
// path: string
|
|
46
|
+
// ) => {
|
|
47
|
+
// for (const route of navigation) {
|
|
48
|
+
// if (route.link === path) {
|
|
49
|
+
// return {
|
|
50
|
+
// exists: true,
|
|
51
|
+
// isParent: false,
|
|
52
|
+
// route,
|
|
53
|
+
// };
|
|
54
|
+
// }
|
|
55
|
+
// if (path.startsWith(route.link)) {
|
|
56
|
+
// return {
|
|
57
|
+
// exists: false,
|
|
58
|
+
// isParent: true,
|
|
59
|
+
// route,
|
|
60
|
+
// };
|
|
61
|
+
// }
|
|
62
|
+
// if (route.children) {
|
|
63
|
+
// const result = checkIfRouteExists(route.children, path);
|
|
64
|
+
// if (result.exists) {
|
|
65
|
+
// return result;
|
|
66
|
+
// }
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
// return {
|
|
70
|
+
// exists: false,
|
|
71
|
+
// isParent: false,
|
|
72
|
+
// route: null,
|
|
73
|
+
// };
|
|
74
|
+
// };
|
|
75
|
+
//# sourceMappingURL=generate-navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-navigation.js","sourceRoot":"","sources":["../../src/utils/generate-navigation.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,8CAA8C;AAC9C,2DAA2D;AAE3D,mEAAmE;AACnE,kDAAkD;AAElD,mDAAmD;AAEnD,gCAAgC;AAChC,sCAAsC;AACtC,qBAAqB;AACrB,WAAW;AAEX,8DAA8D;AAC9D,oBAAoB;AACpB,kBAAkB;AAClB,SAAS;AAET,oBAAoB;AACpB,kBAAkB;AAClB,QAAQ;AAER,sBAAsB;AACtB,8BAA8B;AAC9B,sCAAsC;AACtC,2BAA2B;AAC3B,kCAAkC;AAClC,YAAY;AAEZ,kBAAkB;AAClB,QAAQ;AAER,wBAAwB;AACxB,oCAAoC;AACpC,yBAAyB;AACzB,kBAAkB;AAClB,sBAAsB;AACtB,UAAU;AACV,MAAM;AAEN,6CAA6C;AAC7C,2BAA2B;AAC3B,0CAA0C;AAC1C,wCAAwC;AACxC,qBAAqB;AACrB,oDAAoD;AACpD,aAAa;AACb,SAAS;AAET,uBAAuB;AACvB,KAAK;AAEL,+BAA+B;AAC/B,uCAAuC;AACvC,iBAAiB;AACjB,SAAS;AACT,sCAAsC;AACtC,iCAAiC;AACjC,iBAAiB;AACjB,wBAAwB;AACxB,2BAA2B;AAC3B,iBAAiB;AACjB,WAAW;AACX,QAAQ;AAER,yCAAyC;AACzC,iBAAiB;AACjB,yBAAyB;AACzB,0BAA0B;AAC1B,iBAAiB;AACjB,WAAW;AACX,QAAQ;AAER,4BAA4B;AAC5B,iEAAiE;AAEjE,6BAA6B;AAC7B,yBAAyB;AACzB,UAAU;AACV,QAAQ;AACR,MAAM;AAEN,aAAa;AACb,qBAAqB;AACrB,uBAAuB;AACvB,mBAAmB;AACnB,OAAO;AACP,KAAK"}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
declare const plugin: () => (Promise<{
|
|
2
|
+
name: string;
|
|
3
|
+
enforce: string;
|
|
4
|
+
config(config: unknown, env: any): void;
|
|
5
|
+
configResolved(resolvedConfig: unknown): void;
|
|
6
|
+
transform(code: string, id: string): Promise<{
|
|
7
|
+
code: string;
|
|
8
|
+
map: any;
|
|
9
|
+
}>;
|
|
10
|
+
}> | {
|
|
11
|
+
name: string;
|
|
12
|
+
config: () => {
|
|
13
|
+
define: {
|
|
14
|
+
process: NodeJS.Process;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
enforce: string;
|
|
18
|
+
apply: string;
|
|
19
|
+
})[];
|
|
2
20
|
export { plugin };
|
package/lib/utils/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import mdxPlugin from './plugin.js';
|
|
2
|
+
import polyfill from './polyfill.js';
|
|
3
|
+
// import { generateNavigation } from './generate-navigation.js';
|
|
4
|
+
const plugin = () => [mdxPlugin(), polyfill()];
|
|
2
5
|
export { plugin };
|
|
3
6
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,iEAAiE;AAEjE,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import rehypeStringify from
|
|
2
|
-
import remarkGfm from
|
|
3
|
-
import remarkParse from
|
|
4
|
-
import remarkRehype from
|
|
5
|
-
import { unified } from
|
|
1
|
+
import rehypeStringify from 'rehype-stringify';
|
|
2
|
+
import remarkGfm from 'remark-gfm';
|
|
3
|
+
import remarkParse from 'remark-parse';
|
|
4
|
+
import remarkRehype from 'remark-rehype';
|
|
5
|
+
import { unified } from 'unified';
|
|
6
6
|
export default async function markToHtml(markdown) {
|
|
7
7
|
const file = await unified()
|
|
8
8
|
.use(remarkParse)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mark-to-html.js","sourceRoot":"","sources":["../../src/utils/mark-to-html.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;
|
|
1
|
+
{"version":3,"file":"mark-to-html.js","sourceRoot":"","sources":["../../src/utils/mark-to-html.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IACvD,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE;SACzB,GAAG,CAAC,WAAW,CAAC;SAChB,GAAG,CAAC,SAAS,CAAC;SACd,GAAG,CAAC,YAAY,CAAC;SACjB,GAAG,CAAC,eAAe,CAAC;SACpB,OAAO,CAAC,QAAQ,CAAC,CAAC;IAErB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
|
package/lib/utils/plugin.d.ts
CHANGED
|
@@ -13,21 +13,9 @@ export default function plugin(): Promise<{
|
|
|
13
13
|
name: string;
|
|
14
14
|
enforce: string;
|
|
15
15
|
config(config: unknown, env: any): void;
|
|
16
|
-
/**
|
|
17
|
-
* Stores the resolved Vite configuration for later use.
|
|
18
|
-
*
|
|
19
|
-
* @param resolvedConfig - The resolved Vite configuration object.
|
|
20
|
-
*/
|
|
21
16
|
configResolved(resolvedConfig: unknown): void;
|
|
22
|
-
/**
|
|
23
|
-
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
24
|
-
*
|
|
25
|
-
* @param code - The content of the MDX file.
|
|
26
|
-
* @param id - The ID of the MDX file.
|
|
27
|
-
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
28
|
-
*/
|
|
29
17
|
transform(code: string, id: string): Promise<{
|
|
30
18
|
code: string;
|
|
31
|
-
map:
|
|
19
|
+
map: any;
|
|
32
20
|
}>;
|
|
33
21
|
}>;
|
package/lib/utils/plugin.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import matter from
|
|
2
|
-
import createFilter from
|
|
3
|
-
import remarkGfm from
|
|
4
|
-
import rehypeStringify from
|
|
5
|
-
import remarkParse from
|
|
6
|
-
import remarkRehype from
|
|
7
|
-
import
|
|
8
|
-
import rehypePrettyCode from "rehype-pretty-code";
|
|
1
|
+
import matter from 'gray-matter';
|
|
2
|
+
import createFilter from './create-filter.js';
|
|
3
|
+
import remarkGfm from 'remark-gfm';
|
|
4
|
+
import rehypeStringify from 'rehype-stringify';
|
|
5
|
+
import remarkParse from 'remark-parse';
|
|
6
|
+
import remarkRehype from 'remark-rehype';
|
|
7
|
+
import rehypePrettyCode from 'rehype-pretty-code';
|
|
9
8
|
/**
|
|
10
9
|
* A Vite plugin that transforms MDX files into a format that can be used in a RasenganJs application.
|
|
11
10
|
*
|
|
@@ -18,17 +17,17 @@ import rehypePrettyCode from "rehype-pretty-code";
|
|
|
18
17
|
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
19
18
|
*/
|
|
20
19
|
export default async function plugin() {
|
|
21
|
-
const mdx = (await import(
|
|
20
|
+
const mdx = (await import('@mdx-js/rollup')).default;
|
|
22
21
|
let config;
|
|
23
|
-
const filter = createFilter(
|
|
22
|
+
const filter = createFilter('**/*.md?(x)');
|
|
24
23
|
const mdxInstance = mdx({
|
|
25
24
|
remarkPlugins: [remarkParse, remarkGfm],
|
|
26
25
|
rehypePlugins: [remarkRehype, rehypeStringify, rehypePrettyCode],
|
|
27
26
|
});
|
|
28
27
|
return {
|
|
29
|
-
name:
|
|
28
|
+
name: 'vite-plugin-rasengan-mdx',
|
|
30
29
|
// Apply transformation of the mdx file before other plugins
|
|
31
|
-
enforce:
|
|
30
|
+
enforce: 'pre',
|
|
32
31
|
config(config, env) {
|
|
33
32
|
mdxInstance.config(config, env);
|
|
34
33
|
},
|
|
@@ -55,14 +54,11 @@ export default async function plugin() {
|
|
|
55
54
|
const { content, data: frontmatter } = matter(code);
|
|
56
55
|
// Apply transformation of the mdx file
|
|
57
56
|
const result = await mdxInstance.transform(content, id);
|
|
58
|
-
const toc = await extractToc(content);
|
|
59
|
-
// const html = await markToHtml(content);
|
|
60
|
-
// console.log({ toc });
|
|
61
57
|
// Extract the file name from the path
|
|
62
58
|
const fileName = id
|
|
63
|
-
.split(
|
|
59
|
+
.split('/')
|
|
64
60
|
.pop()
|
|
65
|
-
.replace(/.page.mdx?$/,
|
|
61
|
+
.replace(/.page.mdx?$/, '');
|
|
66
62
|
// TODO: Consider other params of metadata from frontmatter
|
|
67
63
|
const metadata = {
|
|
68
64
|
path: frontmatter.path || `/${fileName}`,
|
package/lib/utils/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/utils/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/utils/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,MAAM;IAalC,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;IAErD,IAAI,MAAe,CAAC;IACpB,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,GAAG,CAAC;QACtB,aAAa,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC;QACvC,aAAa,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,gBAAgB,CAAC;KACjE,CAAC,CAAC;IAEH,OAA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|
3
|
+
name: 'vite-plugin-rasengan-mdx-polyfill',
|
|
4
|
+
config: () => {
|
|
5
|
+
return {
|
|
6
|
+
define: {
|
|
7
|
+
process: process,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
enforce: 'pre',
|
|
12
|
+
apply: 'build',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=polyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/utils/polyfill.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,QAAQ;IAC9B,OAAO;QACL,IAAI,EAAE,mCAAmC;QAEzC,MAAM,EAAE,GAAG,EAAE;YACX,OAAO;gBACL,MAAM,EAAE;oBACN,OAAO,EAAE,OAAO;iBACjB;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;KACf,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,65 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
2
|
+
"name": "@rasenganjs/mdx",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.6",
|
|
5
|
+
"description": "RasenganJS plugin for MDX support",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/index.js",
|
|
11
|
+
"require": "./lib/index.js",
|
|
12
|
+
"types": "./lib/types/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./css": "./lib/styles/rasengan-mdx.min.css",
|
|
15
|
+
"./plugin": {
|
|
16
|
+
"import": "./lib/utils/plugin.js",
|
|
17
|
+
"require": "./lib/utils/plugin.js",
|
|
18
|
+
"types": "./lib/utils/plugin.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "dilane3",
|
|
23
|
+
"email": "komboudilane125@gmail.com",
|
|
24
|
+
"url": "https://dilane3.com",
|
|
25
|
+
"twitter": "https://twitter.com/dilanekombou",
|
|
26
|
+
"github": "https://github.com/dilane3"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/rasengan-dev/rasengan-mdx-plugin.git",
|
|
31
|
+
"issues": "https://github.com/rasengan-dev/rasengan-mdx-plugin/issues"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/clean-css": "^4.2.11",
|
|
36
|
+
"@types/micromatch": "^4.0.7",
|
|
37
|
+
"@types/node": "^22.7.4",
|
|
38
|
+
"@types/react": "^19.0.1",
|
|
39
|
+
"@types/react-dom": "^19.0.1",
|
|
40
|
+
"clean-css": "^5.3.3"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@mdx-js/rollup": "^3.0.1",
|
|
44
|
+
"gray-matter": "^4.0.3",
|
|
45
|
+
"micromatch": "^4.0.7",
|
|
46
|
+
"path-browserify": "^1.0.1",
|
|
47
|
+
"prism-react-renderer": "^2.4.0",
|
|
48
|
+
"react-markdown": "^9.0.1",
|
|
49
|
+
"rehype-pretty-code": "^0.14.0",
|
|
50
|
+
"rehype-stringify": "^10.0.1",
|
|
51
|
+
"remark": "^15.0.1",
|
|
52
|
+
"remark-gfm": "^4.0.0",
|
|
53
|
+
"remark-parse": "^11.0.0",
|
|
54
|
+
"remark-rehype": "^11.1.1",
|
|
55
|
+
"remark-toc": "^9.0.0",
|
|
56
|
+
"shiki": "^1.24.2",
|
|
57
|
+
"unified": "^11.0.5"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": "^19.0.0",
|
|
61
|
+
"react-dom": "^19.0.0"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build:clean": "rm -rf ./lib",
|
|
65
|
+
"build:css": "node ./src/scripts/compile-css.js",
|
|
66
|
+
"build": "pnpm run build:clean && tsc && npm run build:css",
|
|
67
|
+
"pack": "pnpm pack --pack-destination ./release",
|
|
68
|
+
"deploy": "pnpm publish --access public"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
"outDir": "lib",
|
|
4
4
|
"rootDir": "src",
|
|
5
5
|
"target": "ESNext",
|
|
6
|
-
"lib": [
|
|
7
|
-
"ES2015",
|
|
8
|
-
"ESNext",
|
|
9
|
-
"dom",
|
|
10
|
-
"dom.iterable",
|
|
11
|
-
"esnext"
|
|
12
|
-
],
|
|
6
|
+
"lib": ["ES2015", "ESNext", "dom", "dom.iterable", "esnext"],
|
|
13
7
|
"allowJs": true,
|
|
14
8
|
"skipLibCheck": true,
|
|
15
9
|
"esModuleInterop": true,
|
|
@@ -29,10 +23,6 @@
|
|
|
29
23
|
/* Types */
|
|
30
24
|
"typeRoots": ["node_modules/@types", "src/types"]
|
|
31
25
|
},
|
|
32
|
-
"include": [
|
|
33
|
-
"src",
|
|
34
|
-
"src/types",
|
|
35
|
-
"src/styles/*.css"
|
|
36
|
-
],
|
|
26
|
+
"include": ["src", "src/types", "src/styles/*.css"],
|
|
37
27
|
"exclude": ["node_modules", "lib", "src/scripts"]
|
|
38
28
|
}
|