Skip to content

Commit 8d2f127

Browse files
committed
feat: support mermaid
1 parent e2909b0 commit 8d2f127

21 files changed

+974
-5420
lines changed

__tests__/example.spec.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
// example.spec.ts
22
import { test, expect } from '@playwright/test';
3-
import {default as domains} from '../domains.json';
3+
import { default as domains } from '../domains.json';
44

55
const stagingUrl = 'https://staging-docs-page-website-euw1-dzpolnxswq-ew.a.run.app';
66

77
// skip these as these are not working (user error)
8-
const skipList = ['dokumentacja.otwartaturystyka.pl']
8+
const skipList = ['dokumentacja.otwartaturystyka.pl'];
99

1010
domains.forEach(domain => {
11-
if (!skipList.includes(domain[0])) {
11+
if (!skipList.includes(domain[0])) {
1212
test(`${domain[0]}`, async ({ page }) => {
13+
const response = await page.goto(`https://${domain[0]}`);
1314

14-
const response = await page.goto(`https://${domain[0]}`);
15+
expect(response).toBeDefined();
16+
expect(response!.status()).toBe(200);
1517

16-
expect(response).toBeDefined();
17-
expect(response!.status()).toBe(200);
18+
const screenshotName = `${domain[1]}-original.png`;
19+
await expect(page).toHaveScreenshot(screenshotName);
1820

19-
const screenshotName = `${domain[1]}-original.png`;
20-
await expect(page).toHaveScreenshot(`${domain[1]}-original.png`);
21-
22-
await page.goto(`${stagingUrl}/${domain[1]}`)
23-
await expect(page).toHaveScreenshot(`${domain[1]}-original.png`);
21+
await page.goto(`${stagingUrl}/${domain[1]}`);
22+
await expect(page).toHaveScreenshot(screenshotName);
2423
});
25-
}
26-
})
24+
}
25+
});
Binary file not shown.
Binary file not shown.

api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"js-yaml": "^4.1.0",
2929
"lodash.get": "^4.4.2",
3030
"mdx-bundler": "^9.0.1",
31+
"mermaid": "^9.1.7",
3132
"morgan": "^1.10.0",
3233
"node-fetch": "^3.2.6",
3334
"probot": "^12.2.4",

api/src/bundler/getPlugins.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import remarkComment from 'remark-comment';
1212

1313
function getPlugins(config: OutputConfig) {
1414
//
15+
1516
const remarkPlugins = config?.experimentalCodehike
1617
? [remarkGfm, remarkComment, [remarkCodeHike, { theme, lineNumbers: true }]]
1718
: [remarkGfm, remarkComment];
@@ -23,6 +24,7 @@ function getPlugins(config: OutputConfig) {
2324
if (config?.experimentalMath) {
2425
//@ts-ignore
2526
remarkPlugins.push(remarkMath);
27+
//@ts-ignore
2628
rehypePlugins.push(rehypeKatex);
2729
}
2830
return { remarkPlugins, rehypePlugins };

api/src/bundler/plugins/rehype-code-blocks.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { visit } from 'unist-util-visit';
44
import { Node } from 'hast-util-heading-rank';
55
import { toString } from 'mdast-util-to-string';
66
import * as shiki from 'shiki';
7-
87
let highlighter: shiki.Highlighter;
98

109
/**
1110
* Matches any `pre code` elements and extracts the raw code and titles from the code block and assigns to the parent.
1211
* @returns
1312
*/
1413
export default function rehypeCodeBlocks(): (ast: Node) => void {
15-
function visitor(node: any, _i: number, parent: any) {
14+
function visitor(node: any, i: number, parent: any) {
1615
if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') {
1716
return;
1817
}
@@ -21,6 +20,21 @@ export default function rehypeCodeBlocks(): (ast: Node) => void {
2120

2221
const raw = toString(node);
2322

23+
if (language === 'mermaid') {
24+
Object.assign(parent, {
25+
type: 'mdxJsxFlowElement',
26+
name: 'Mermaid',
27+
attributes: [
28+
{
29+
type: 'mdxJsxAttribute',
30+
name: 'chart',
31+
value: node.children[0].value,
32+
},
33+
],
34+
});
35+
return;
36+
}
37+
2438
// If the user provides the `console` language, we add the 'shell' language and remove $ from the raw code, for copying purposes.
2539
if (language === 'console') {
2640
const removedDollarSymbol = raw.replace(/^(^ *)\$/g, '');

packages/server/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"devDependencies": {
1616
"@types/node-fetch": "^2.6.2",
17+
"@types/pino-std-serializers": "^4.0.0",
1718
"esbuild": "^0.14.47",
1819
"typescript": "^4.5.4"
1920
},

playwright.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const config: PlaywrightTestConfig = {
1919
* Maximum time expect() should wait for the condition to be met.
2020
* For example in `await expect(locator).toHaveText();`
2121
*/
22-
timeout: 5000
22+
timeout: 5000,
2323
},
2424
/* Run tests in files in parallel */
2525
fullyParallel: true,
@@ -49,7 +49,7 @@ const config: PlaywrightTestConfig = {
4949
use: {
5050
...devices['Desktop Chrome'],
5151
},
52-
}
52+
},
5353

5454
/* Test against mobile viewports. */
5555
// {

website/app/components/mdx/index.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Pre } from './Pre';
99
import { Tabs, TabItem } from './Tabs';
1010
import { Vimeo } from './Vimeo';
1111
import { Tweet } from './Tweet';
12+
import { Mermaid } from 'mdx-mermaid/lib/Mermaid';
1213

1314
function Anchor(
1415
props: DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>,
@@ -72,4 +73,9 @@ export default {
7273
TabItem,
7374
Tweet,
7475
Vimeo,
76+
Mermaid: ({ chart }: { chart: string }) => {
77+
console.log('here', chart);
78+
79+
return <Mermaid chart={chart} />;
80+
},
7581
};

website/app/entry.client.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ hydrateRoot(
2424
<BrowserRouter>
2525
<RemixBrowser />
2626
</BrowserRouter>,
27-
);
27+
);

website/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"detect-browser": "^5.3.0",
3737
"express": "^4.18.1",
3838
"lodash.get": "^4.4.2",
39+
"mdx-mermaid": "^v1.3.0",
40+
"mermaid": "^9.1.7",
3941
"morgan": "^1.10.0",
4042
"nprogress": "^0.2.0",
4143
"react": "^18.2.0",

0 commit comments

Comments
 (0)