Repository: graphql-markdown/graphql-markdown (ts)

Issue:
Compatibility with Docusaurus v3
Docusaurus 3.0 has been released 🎉 

We need to provide compatibility with both v2 and v3.

MDX v3 is more restrictive and will require to escape characters: https://mdxjs.com/docs/troubleshooting-mdx/#problems-writing-mdx


Pull request:
add docusaurus v3 support
# Description

Closes #1069 

# Checklist

- [x] My changes follow the [contributing guidelines](https://github.com/graphql-markdown/graphql-markdown/blob/main/CONTRIBUTING.md) of this project.
- [x] I have performed a self-review of my code.
- [ ] I have made corresponding changes to the documentation.
- [x] I have added tests that prove my fix is effective or that my changes work.
- [x] New and existing unit tests pass locally with my changes.


Patch:
diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml
index 168773f2..b1efbcb4 100644
--- a/.github/workflows/smoke.yml
+++ b/.github/workflows/smoke.yml
@@ -25,7 +25,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        docusaurus: [2]
+        docusaurus: [2, 3]
     steps:
       - name: Install earthly
         uses: earthly/actions-setup@v1
diff --git a/packages/printer-legacy/src/common.ts b/packages/printer-legacy/src/common.ts
index a47e8ecc..fd5b1ebf 100644
--- a/packages/printer-legacy/src/common.ts
+++ b/packages/printer-legacy/src/common.ts
@@ -46,6 +46,9 @@ export const printCustomDirectives = (
     .filter((text) => {
       return typeof text === "string" && text.length > 0;
     })
+    .map((text) => {
+      return escapeMDX(text);
+    })
     .join(MARKDOWN_EOP);
 
   return `${MARKDOWN_EOP}${content}`;
@@ -56,14 +59,14 @@ export const formatDescription = (
   replacement: Maybe<string> = NO_DESCRIPTION_TEXT,
 ): MDXString | string => {
   if (typeof type !== "object" || type === null) {
-    return `${MARKDOWN_EOP}${replacement}`;
+    return `${MARKDOWN_EOP}${escapeMDX(replacement)}`;
   }
 
   const description =
     "description" in type && typeof type.description === "string"
-      ? escapeMDX(type.description)
+      ? type.description
       : replacement;
-  return `${MARKDOWN_EOP}${description}`;
+  return `${MARKDOWN_EOP}${escapeMDX(description)}`;
 };
 
 export const printDeprecation = (type: unknown): string => {
@@ -73,7 +76,7 @@ export const printDeprecation = (type: unknown): string => {
 
   const reason =
     "deprecationReason" in type && typeof type.deprecationReason === "string"
-      ? type.deprecationReason + MARKDOWN_EOL
+      ? escapeMDX(type.deprecationReason) + MARKDOWN_EOL
       : "";
 
   return `${MARKDOWN_EOP}:::caution ${DEPRECATED.toUpperCase()}${MARKDOWN_EOL}${reason}:::`;


Test patch:
diff --git a/packages/printer-legacy/tests/unit/common.test.ts b/packages/printer-legacy/tests/unit/common.test.ts
index 1a245fce..6a2cd038 100644
--- a/packages/printer-legacy/tests/unit/common.test.ts
+++ b/packages/printer-legacy/tests/unit/common.test.ts
@@ -128,7 +128,7 @@ describe("common", () => {
       const type = {
         description: "Lorem ipsum",
         isDeprecated: true,
-        deprecationReason: "Foobar",
+        deprecationReason: "{ Foobar }",
       };
       const description = printDescription(type);
 
@@ -136,7 +136,7 @@ describe("common", () => {
         "
 
         :::caution DEPRECATED
-        Foobar
+        &#x007B; Foobar &#x007D;
         :::
 
         Lorem ipsum"
@@ -215,7 +215,7 @@ describe("common", () => {
       const type = {
         name: "EntityTypeName",
         isDeprecated: true,
-        deprecationReason: "foobar",
+        deprecationReason: "{ foobar }",
       };
       const deprecation = printDeprecation(type);
 
@@ -223,7 +223,7 @@ describe("common", () => {
         "
 
         :::caution DEPRECATED
-        foobar
+        &#x007B; foobar &#x007D;
         :::"
       `);
     });