Skip to content

Commit 692cf1a

Browse files
committed
Switch out @theguild/remark-mermaid to for rehype-mermaid
1 parent b607bad commit 692cf1a

File tree

4 files changed

+138
-6
lines changed

4 files changed

+138
-6
lines changed

next.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-env node */
2+
// @ts-check
23

34
import nextra from "nextra"
45
import path from "node:path"
56
import withLess from "next-with-less"
67
import nextBundleAnalyzer from "@next/bundle-analyzer"
78
import fs from "fs"
9+
import rehypeMermaid from "rehype-mermaid"
810

911
import { remarkGraphiQLComment } from "./src/remark-graphiql-comment.js"
1012
import { syntaxHighlightingThemes } from "./src/_design-system/syntax/index.js"
@@ -17,6 +19,7 @@ const withNextra = nextra({
1719
themeConfig: "./theme.config.tsx",
1820
mdxOptions: {
1921
remarkPlugins: [remarkGraphiQLComment],
22+
rehypePlugins: [mermaidConfig()],
2023
rehypePrettyCodeOptions: {
2124
theme: syntaxHighlightingThemes,
2225
},
@@ -173,6 +176,35 @@ const config = {
173176

174177
const withBundleAnalyzer = nextBundleAnalyzer({
175178
enabled: process.env.ANALYZE === "true",
179+
analyzerMode: "json",
176180
})
177181

178182
export default withBundleAnalyzer(withLess(withNextra(config)))
183+
184+
function mermaidConfig() {
185+
return [
186+
rehypeMermaid,
187+
/** @type {import("rehype-mermaid").RehypeMermaidOptions} */ ({
188+
mermaidConfig: {
189+
fontFamily: "var(--font-mono, monospace)",
190+
theme: "base",
191+
look: "classic",
192+
themeVariables: {
193+
background: "var(--color-neu-0)",
194+
primaryColor: "var(--color-sec-base)",
195+
primaryTextColor: "var(--color-neu-900)",
196+
primaryBorderColor: "var(--color-pri-base)",
197+
secondaryColor: "var(--color-pri-base)",
198+
secondaryTextColor: "var(--color-neu-900)",
199+
secondaryBorderColor: "var(--color-pri-base)",
200+
tertiaryColor: "var(--color-pri-base)",
201+
tertiaryTextColor: "var(--color-neu-900)",
202+
tertiaryBorderColor: "var(--color-pri-base)",
203+
textColor: "var(--color-neu-900)",
204+
mainBkg: "var(--color-neu-100)",
205+
lineColor: "var(--color-neu-400)",
206+
},
207+
},
208+
}),
209+
]
210+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"react-dom": "^18.3.1",
6464
"react-medium-image-zoom": "5.2.13",
6565
"react-use-measure": "^2.1.7",
66+
"rehype-mermaid": "^3.0.0",
6667
"rss": "1.2.2",
6768
"server-only": "0.0.1",
6869
"string-similarity": "^4.0.4",

patches/nextra.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ index 239d72f5921e2d1b7359e569ae5b74c12d7c9d8a..ebeb619da1e3ccb7722e9388c92c1e21
99
import { forwardRef } from "react";
1010
const Image = forwardRef((props, ref) => {
1111
const ComponentToUse = typeof props.src === "object" ? NextImage : "img";
12+
diff --git a/dist/client/components/index.js b/dist/client/components/index.js
13+
index 9d05118d3d10e746cd2c020785a0f34465bb8570..218107600d7efed1b5f9d49f0a696b166917d1ce 100644
14+
--- a/dist/client/components/index.js
15+
+++ b/dist/client/components/index.js
16+
@@ -14,7 +14,7 @@ import { Tabs } from "./tabs/index.js";
17+
import { Td } from "./td.js";
18+
import { Th } from "./th.js";
19+
import { Tr } from "./tr.js";
20+
-import { Mermaid } from "@theguild/remark-mermaid/mermaid";
21+
+// import { Mermaid } from "@theguild/remark-mermaid/mermaid";
22+
import { MathJax, MathJaxContext } from "better-react-mathjax";
23+
import { Playground } from "./playground.js";
24+
import { Popup } from "./popup.js";
25+
@@ -29,7 +29,7 @@ export {
26+
ImageZoom,
27+
MathJax,
28+
MathJaxContext,
29+
- Mermaid,
30+
+ // Mermaid, // disabled to use rehype-mermaid and remove cytoscape from the bundle
31+
Playground,
32+
Popup,
33+
Pre,
1234
diff --git a/dist/client/normalize-pages.js b/dist/client/normalize-pages.js
1335
index 15afee0c1de26f47d781f423e5ec32e33ad925d3..fefd01736bd2b778df275bf50ac48384d5f63845 100644
1436
--- a/dist/client/normalize-pages.js
@@ -24,3 +46,24 @@ index 15afee0c1de26f47d781f423e5ec32e33ad925d3..fefd01736bd2b778df275bf50ac48384
2446
if (!isValid) {
2547
throw new Error(
2648
`Validation of "_meta" file has failed.
49+
diff --git a/dist/server/compile.js b/dist/server/compile.js
50+
index c266efec3fe344a81c6d5791b93ab1b2bd268782..4866148a725800ef2326732f78807cca0f04cb7b 100644
51+
--- a/dist/server/compile.js
52+
+++ b/dist/server/compile.js
53+
@@ -1,6 +1,6 @@
54+
import path from "path";
55+
import { createProcessor } from "@mdx-js/mdx";
56+
-import { remarkMermaid } from "@theguild/remark-mermaid";
57+
+// import { remarkMermaid } from "@theguild/remark-mermaid";
58+
import { remarkNpm2Yarn } from "@theguild/remark-npm2yarn";
59+
import rehypeKatex from "rehype-katex";
60+
import rehypePrettyCode from "rehype-pretty-code";
61+
@@ -143,7 +143,7 @@ async function compileMdx(source, {
62+
development: process.env.NODE_ENV === "development",
63+
remarkPlugins: [
64+
...remarkPlugins || [],
65+
- remarkMermaid,
66+
+ // remarkMermaid, // disabled to use rehype-mermaid and remove cytoscape from the bundle
67+
// should be before remarkRemoveImports because contains `import { Mermaid } from ...`
68+
[
69+
remarkNpm2Yarn,

pnpm-lock.yaml

Lines changed: 62 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)