@studiocms/mdx 0.1.0-beta.13

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 StudioCMS - Adam Matthiesen, Jacob Jenkins, Paul Valladares
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @StudioCMS/MDX Plugin
2
+
3
+ Add MDX support to StudioCMS
4
+
5
+ ## Usage
6
+
7
+ Add this plugin in your StudioCMS config. (`studiocms.config.mjs`)
8
+
9
+ ```ts
10
+ import { defineStudioCMSConfig } from 'studiocms/config';
11
+ import mdxPlugin from '@studiocms/mdx';
12
+
13
+ export default defineStudioCMSConfig({
14
+ // other options here
15
+ plugins: [mdxPlugin()]
16
+ });
17
+ ```
18
+
19
+ ## Options
20
+
21
+ ### remarkPlugins
22
+ **Type:** `PluggableList` | `undefined`
23
+
24
+ Optional list of Remark plugins
25
+
26
+ ### rehypePlugins
27
+ **Type:** `PluggableList` | `undefined`
28
+
29
+ Optional list of Rehype plugins
30
+
31
+ ### recmaPlugins
32
+ **Type:** `PluggableList` | `undefined`
33
+
34
+ Optional list of recma plugins
35
+
36
+ ### remarkRehypeOptions
37
+ **Type:** `remarkRehypeOptions` | `undefined`
38
+
39
+ Optional: options for remarkRehype
40
+
41
+ ## License
42
+
43
+ [MIT Licensed](./LICENSE).
@@ -0,0 +1,15 @@
1
+ ---
2
+ import renderMDX from 'studiocms:mdx/renderer';
3
+ import type { PluginPageTypeRendererProps } from 'studiocms/types';
4
+
5
+ interface Props extends PluginPageTypeRendererProps {}
6
+
7
+ // Get default content
8
+ const { defaultContent } = Astro.props.data;
9
+
10
+ // Get content to render
11
+ const contentToRender = defaultContent?.content || '# Error: No content found';
12
+
13
+ const renderedContent = await renderMDX(contentToRender);
14
+ ---
15
+ <Fragment set:html={renderedContent} />
@@ -0,0 +1,28 @@
1
+ /**
2
+ * These triple-slash directives defines dependencies to various declaration files that will be
3
+ * loaded when a user imports the StudioCMS plugin in their Astro configuration file. These
4
+ * directives must be first at the top of the file and can only be preceded by this comment.
5
+ */
6
+ /// <reference types="./virtual.d.ts" preserve="true" />
7
+ import { type StudioCMSPlugin } from 'studiocms/plugins';
8
+ import type { MDXPluginOptions } from './types.js';
9
+ /**
10
+ * Creates and configures the StudioCMS MDX plugin.
11
+ *
12
+ * @param {MDXPluginOptions} [options] - Optional configuration options for the MDX plugin.
13
+ * @returns {StudioCMSPlugin} The configured StudioCMS plugin.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * plugins: [
18
+ * studiocmsMDX({
19
+ * remarkPlugins: [],
20
+ * rehypePlugins: [],
21
+ * recmaPlugins: [],
22
+ * remarkRehypeOptions: {}
23
+ * }),
24
+ * ]
25
+ * ```
26
+ */
27
+ export declare function studiocmsMDX(options?: MDXPluginOptions): StudioCMSPlugin;
28
+ export default studiocmsMDX;
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ import { addVirtualImports, createResolver } from "astro-integration-kit";
2
+ import { definePlugin } from "studiocms/plugins";
3
+ import { shared } from "./lib/shared.js";
4
+ function studiocmsMDX(options) {
5
+ const { resolve } = createResolver(import.meta.url);
6
+ const packageIdentifier = "@studiocms/mdx";
7
+ const renderer = resolve("./components/MDXRenderer.astro");
8
+ const internalRenderer = resolve("./lib/render.js");
9
+ const resolvedOptions = {
10
+ remarkPlugins: options?.remarkPlugins || [],
11
+ rehypePlugins: options?.rehypePlugins || [],
12
+ recmaPlugins: options?.recmaPlugins || [],
13
+ remarkRehypeOptions: options?.remarkRehypeOptions || {}
14
+ };
15
+ return definePlugin({
16
+ identifier: packageIdentifier,
17
+ name: "StudioCMS MDX",
18
+ studiocmsMinimumVersion: "0.1.0-beta.12",
19
+ pageTypes: [
20
+ // Define the MDX page type
21
+ {
22
+ identifier: "studiocms/mdx",
23
+ label: "MDX",
24
+ pageContentComponent: "studiocms/markdown",
25
+ // Fallback to the default content editor for now, might build a custom MDX editor in the future
26
+ rendererComponent: renderer
27
+ }
28
+ ],
29
+ integration: {
30
+ name: packageIdentifier,
31
+ hooks: {
32
+ "astro:config:setup": (params) => {
33
+ addVirtualImports(params, {
34
+ name: packageIdentifier,
35
+ imports: {
36
+ "studiocms:mdx/renderer": `
37
+ import { renderMDX as _render } from '${internalRenderer}';
38
+
39
+ export const renderMDX = _render;
40
+ export default renderMDX;
41
+ `
42
+ }
43
+ });
44
+ },
45
+ "astro:config:done": () => {
46
+ shared.mdxConfig = resolvedOptions;
47
+ }
48
+ }
49
+ }
50
+ });
51
+ }
52
+ var index_default = studiocmsMDX;
53
+ export {
54
+ index_default as default,
55
+ studiocmsMDX
56
+ };
@@ -0,0 +1,2 @@
1
+ export declare function renderMDX(content: string): Promise<string>;
2
+ export default renderMDX;
@@ -0,0 +1,35 @@
1
+ import { evaluate } from "@mdx-js/mdx";
2
+ import { createElement } from "react";
3
+ import { renderToString } from "react-dom/server";
4
+ import * as runtime from "react/jsx-runtime";
5
+ import rehypeHighlight from "rehype-highlight";
6
+ import remarkGfm from "remark-gfm";
7
+ import { shared } from "./shared.js";
8
+ const baseRemarkPlugins = [remarkGfm];
9
+ const baseRehypePlugins = [rehypeHighlight];
10
+ const { recmaPlugins, rehypePlugins, remarkPlugins, remarkRehypeOptions } = shared.mdxConfig;
11
+ const makeList = (included, userDefinedPlugins) => {
12
+ const Plugins = included;
13
+ if (userDefinedPlugins) {
14
+ for (const plugin of userDefinedPlugins) {
15
+ Plugins.push(plugin);
16
+ }
17
+ }
18
+ return Plugins;
19
+ };
20
+ async function renderMDX(content) {
21
+ const { default: MDXContent } = await evaluate(content, {
22
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
23
+ ...runtime,
24
+ remarkPlugins: makeList(baseRemarkPlugins, remarkPlugins),
25
+ rehypePlugins: makeList(baseRehypePlugins, rehypePlugins),
26
+ recmaPlugins,
27
+ remarkRehypeOptions
28
+ });
29
+ return renderToString(createElement(MDXContent));
30
+ }
31
+ var render_default = renderMDX;
32
+ export {
33
+ render_default as default,
34
+ renderMDX
35
+ };
@@ -0,0 +1,14 @@
1
+ import type { MDXPluginOptions } from '../types.js';
2
+ export declare const symbol: symbol;
3
+ /**
4
+ * A shared object that is either retrieved from the global scope using a symbol or
5
+ * initialized as a new object with a `mdxConfig` property.
6
+ *
7
+ * @remarks
8
+ * The `@ts-ignore` comments are used to suppress TypeScript errors related to the use of
9
+ * the global scope and assignment within expressions. The `biome-ignore` comment is used
10
+ * to suppress linting errors for the same reason.
11
+ */
12
+ export declare const shared: {
13
+ mdxConfig: MDXPluginOptions;
14
+ };
@@ -0,0 +1,13 @@
1
+ const symbol = Symbol.for("@studiocms/mdx");
2
+ const shared = (
3
+ // @ts-ignore
4
+ globalThis[symbol] || // @ts-ignore
5
+ // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
6
+ (globalThis[symbol] = {
7
+ mdxConfig: {}
8
+ })
9
+ );
10
+ export {
11
+ shared,
12
+ symbol
13
+ };
@@ -0,0 +1,8 @@
1
+ import type { EvaluateOptions } from '@mdx-js/mdx';
2
+ import type { PluggableList } from 'unified';
3
+ export interface MDXPluginOptions {
4
+ remarkPlugins?: PluggableList;
5
+ rehypePlugins?: PluggableList;
6
+ recmaPlugins?: PluggableList;
7
+ remarkRehypeOptions?: EvaluateOptions['remarkRehypeOptions'];
8
+ }
package/dist/types.js ADDED
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ declare module 'studiocms:mdx/renderer' {
2
+ export const renderMDX: typeof import('./lib/render').renderMDX;
3
+ export default renderMDX;
4
+ }
5
+
6
+ declare module 'virtual:studiocms/plugins/renderers' {
7
+ export const studiocms_mdx: typeof import('./components/MDXRenderer.astro').default;
8
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@studiocms/mdx",
3
+ "version": "0.1.0-beta.13",
4
+ "description": "Add MDX Support to your StudioCMS project with ease!",
5
+ "author": {
6
+ "name": "Adam Matthiesen | Jacob Jenkins | Paul Valladares",
7
+ "url": "https://studiocms.dev"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/withstudiocms/studiocms.git",
12
+ "directory": "packages/studiocms_mdx"
13
+ },
14
+ "contributors": [
15
+ "Adammatthiesen",
16
+ "jdtjenkins",
17
+ "dreyfus92",
18
+ "code.spirit"
19
+ ],
20
+ "license": "MIT",
21
+ "keywords": [
22
+ "astro",
23
+ "astrocms",
24
+ "astrodb",
25
+ "astrostudio",
26
+ "astro-integration",
27
+ "astro-studio",
28
+ "astro-studiocms",
29
+ "cms",
30
+ "studiocms",
31
+ "withastro",
32
+ "plugin",
33
+ "studiocms-plugin"
34
+ ],
35
+ "homepage": "https://studiocms.dev",
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true
39
+ },
40
+ "sideEffects": false,
41
+ "files": [
42
+ "dist"
43
+ ],
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.ts",
47
+ "default": "./dist/index.js"
48
+ },
49
+ "./types": {
50
+ "types": "./dist/types.d.ts",
51
+ "default": "./dist/types.js"
52
+ },
53
+ "./v/types": {
54
+ "types": "./dist/virtual.d.ts",
55
+ "default": "./dist/virtual.d.js"
56
+ }
57
+ },
58
+ "type": "module",
59
+ "dependencies": {
60
+ "@mdx-js/mdx": "^3.1.0",
61
+ "astro-integration-kit": "^0.18",
62
+ "react": "^19.0.0",
63
+ "react-dom": "^19.0.0",
64
+ "rehype-highlight": "^7.0.2",
65
+ "remark-gfm": "^4.0.1",
66
+ "unified": "^11.0.5"
67
+ },
68
+ "devDependencies": {
69
+ "@types/node": "^22.0.0",
70
+ "@types/react": "^19.0.12",
71
+ "@types/react-dom": "^19.0.4"
72
+ },
73
+ "peerDependencies": {
74
+ "astro": "^5.5.0",
75
+ "vite": "^6.2.0",
76
+ "studiocms": "0.1.0-beta.13"
77
+ },
78
+ "scripts": {
79
+ "build": "build-scripts build 'src/**/*.ts'",
80
+ "dev": "build-scripts dev 'src/**/*.ts'"
81
+ }
82
+ }