@studiocms/markdoc 0.1.0-beta.25 → 0.1.0-beta.27

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # @StudioCMS/MarkDoc Plugin
2
2
 
3
+ [![codecov](https://codecov.io/github/withstudiocms/studiocms/graph/badge.svg?token=RN8LT1O5E2&component=studiocms_markdoc)](https://codecov.io/github/withstudiocms/studiocms)
4
+
3
5
  Add MarkDoc support to StudioCMS
4
6
 
5
7
  ## Usage
package/dist/index.d.ts CHANGED
@@ -4,7 +4,17 @@
4
4
  * directives must be first at the top of the file and can only be preceded by this comment.
5
5
  */
6
6
  /// <reference types="./virtual.d.ts" preserve="true" />
7
+ import type { AstroIntegration } from 'astro';
7
8
  import { type StudioCMSPlugin } from 'studiocms/plugins';
8
9
  import type { MarkDocPluginOptions } from './types.js';
10
+ /**
11
+ * Creates an internal Astro integration for MarkDoc rendering.
12
+ * This is used for testing and internal purposes.
13
+ *
14
+ * @param {string} packageIdentifier - The package identifier for the integration.
15
+ * @param {MarkDocPluginOptions} [options] - Optional configuration options for the MarkDoc plugin.
16
+ * @returns {AstroIntegration} The configured Astro integration.
17
+ */
18
+ export declare function internalMarkDocIntegration(packageIdentifier: string, options?: MarkDocPluginOptions): AstroIntegration;
9
19
  export declare function studiocmsMarkDoc(options?: MarkDocPluginOptions): StudioCMSPlugin;
10
20
  export default studiocmsMarkDoc;
package/dist/index.js CHANGED
@@ -1,12 +1,41 @@
1
1
  import { addVirtualImports, createResolver } from "astro-integration-kit";
2
2
  import { definePlugin } from "studiocms/plugins";
3
3
  import { shared } from "./lib/shared.js";
4
+ function internalMarkDocIntegration(packageIdentifier, options) {
5
+ const { resolve } = createResolver(import.meta.url);
6
+ const internalRenderer = resolve("./lib/render.js");
7
+ const resolvedOptions = {
8
+ type: options?.type || "html",
9
+ argParse: options?.argParse,
10
+ transformConfig: options?.transformConfig
11
+ };
12
+ return {
13
+ name: packageIdentifier,
14
+ hooks: {
15
+ "astro:config:setup": (params) => {
16
+ addVirtualImports(params, {
17
+ name: packageIdentifier,
18
+ imports: {
19
+ "studiocms:markdoc/renderer": `
20
+ import { renderMarkDoc as _render } from '${internalRenderer}';
21
+
22
+ export const renderMarkDoc = _render;
23
+ export default renderMarkDoc;
24
+ `
25
+ }
26
+ });
27
+ },
28
+ "astro:config:done": () => {
29
+ shared.markDocConfig = resolvedOptions;
30
+ }
31
+ }
32
+ };
33
+ }
4
34
  function studiocmsMarkDoc(options) {
5
35
  const { resolve } = createResolver(import.meta.url);
6
36
  const packageIdentifier = "@studiocms/markdoc";
7
37
  const renderer = resolve("./components/MarkDocRenderer.astro");
8
38
  const editor = resolve("./components/editor.astro");
9
- const internalRenderer = resolve("./lib/render.js");
10
39
  const resolvedOptions = {
11
40
  type: options?.type || "html",
12
41
  argParse: options?.argParse,
@@ -19,26 +48,7 @@ function studiocmsMarkDoc(options) {
19
48
  requires: ["@studiocms/md"],
20
49
  hooks: {
21
50
  "studiocms:astro:config": ({ addIntegrations }) => {
22
- addIntegrations({
23
- name: packageIdentifier,
24
- hooks: {
25
- "astro:config:setup": (params) => {
26
- addVirtualImports(params, {
27
- name: packageIdentifier,
28
- imports: {
29
- "studiocms:markdoc/renderer": `
30
- import { renderMarkDoc as _render } from '${internalRenderer}';
31
- export const renderMarkDoc = _render;
32
- export default renderMarkDoc;
33
- `
34
- }
35
- });
36
- },
37
- "astro:config:done": () => {
38
- shared.markDocConfig = resolvedOptions;
39
- }
40
- }
41
- });
51
+ addIntegrations(internalMarkDocIntegration(packageIdentifier, resolvedOptions));
42
52
  },
43
53
  "studiocms:config:setup": ({ setRendering }) => {
44
54
  setRendering({
@@ -59,5 +69,6 @@ function studiocmsMarkDoc(options) {
59
69
  var index_default = studiocmsMarkDoc;
60
70
  export {
61
71
  index_default as default,
72
+ internalMarkDocIntegration,
62
73
  studiocmsMarkDoc
63
74
  };
@@ -1,6 +1,5 @@
1
1
  import Markdoc from "@markdoc/markdoc";
2
2
  import { shared } from "./shared.js";
3
- const { argParse, transformConfig, type } = shared.markDocConfig;
4
3
  const renderHTML = {
5
4
  name: "html",
6
5
  render: async (content) => {
@@ -14,6 +13,7 @@ const renderReactStatic = {
14
13
  }
15
14
  };
16
15
  async function renderMarkDoc(content) {
16
+ const { argParse, transformConfig, type } = shared.markDocConfig;
17
17
  const ast = Markdoc.parse(content, argParse);
18
18
  const MarkDocContent = Markdoc.transform(ast, transformConfig);
19
19
  switch (type) {
@@ -5,7 +5,7 @@ export declare const symbol: symbol;
5
5
  * initialized as a new object with a `markDocConfig` property.
6
6
  *
7
7
  * @remarks
8
- * The `@ts-ignore` comments are used to suppress TypeScript errors related to the use of
8
+ * The `@ts-expect-error` comments are used to suppress TypeScript errors related to the use of
9
9
  * the global scope and assignment within expressions. The `biome-ignore` comment is used
10
10
  * to suppress linting errors for the same reason.
11
11
  */
@@ -1,7 +1,7 @@
1
1
  const symbol = Symbol.for("@studiocms/markdoc");
2
2
  const shared = (
3
- // @ts-ignore
4
- globalThis[symbol] || // @ts-ignore
3
+ // @ts-expect-error
4
+ globalThis[symbol] || // @ts-expect-error
5
5
  // biome-ignore lint/suspicious/noAssignInExpressions: This is a valid use case for assignment in expressions.
6
6
  (globalThis[symbol] = {
7
7
  markDocConfig: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiocms/markdoc",
3
- "version": "0.1.0-beta.25",
3
+ "version": "0.1.0-beta.27",
4
4
  "description": "Add MarkDoc Support to your StudioCMS project with ease!",
5
5
  "author": {
6
6
  "name": "withstudiocms",
@@ -66,16 +66,16 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/node": "^22.0.0",
69
- "@types/react": "^19.1.11",
70
- "@types/react-dom": "^19.1.7"
69
+ "@types/react": "^19.1.13",
70
+ "@types/react-dom": "^19.1.9"
71
71
  },
72
72
  "peerDependencies": {
73
- "@astrojs/react": "^4.3.0",
73
+ "@astrojs/react": "^4.3.1",
74
74
  "astro": "^5.12.9",
75
- "effect": "^3.17.9",
75
+ "effect": "^3.17.14",
76
76
  "vite": "^6.3.4",
77
- "@studiocms/md": "0.1.0-beta.25",
78
- "studiocms": "0.1.0-beta.25"
77
+ "@studiocms/md": "0.1.0-beta.27",
78
+ "studiocms": "0.1.0-beta.27"
79
79
  },
80
80
  "peerDependenciesMeta": {
81
81
  "@astrojs/react": {
@@ -85,6 +85,7 @@
85
85
  "scripts": {
86
86
  "build": "buildkit build 'src/**/*.{ts,astro,css,json,png,d.ts}'",
87
87
  "dev": "buildkit dev 'src/**/*.{ts,astro,css,json,png,d.ts}'",
88
+ "test": "vitest",
88
89
  "typecheck": "tspc -p tsconfig.tspc.json"
89
90
  }
90
91
  }