Skip to content

Commit

Permalink
feat: support mermaid
Browse files Browse the repository at this point in the history
  • Loading branch information
cabljac committed Nov 4, 2022
1 parent e2909b0 commit 8d2f127
Show file tree
Hide file tree
Showing 21 changed files with 974 additions and 5,420 deletions.
25 changes: 12 additions & 13 deletions __tests__/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// example.spec.ts
import { test, expect } from '@playwright/test';
import {default as domains} from '../domains.json';
import { default as domains } from '../domains.json';

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

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

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

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

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

const screenshotName = `${domain[1]}-original.png`;
await expect(page).toHaveScreenshot(`${domain[1]}-original.png`);

await page.goto(`${stagingUrl}/${domain[1]}`)
await expect(page).toHaveScreenshot(`${domain[1]}-original.png`);
await page.goto(`${stagingUrl}/${domain[1]}`);
await expect(page).toHaveScreenshot(screenshotName);
});
}
})
}
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"js-yaml": "^4.1.0",
"lodash.get": "^4.4.2",
"mdx-bundler": "^9.0.1",
"mermaid": "^9.1.7",
"morgan": "^1.10.0",
"node-fetch": "^3.2.6",
"probot": "^12.2.4",
Expand Down
2 changes: 2 additions & 0 deletions api/src/bundler/getPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import remarkComment from 'remark-comment';

function getPlugins(config: OutputConfig) {
//

const remarkPlugins = config?.experimentalCodehike
? [remarkGfm, remarkComment, [remarkCodeHike, { theme, lineNumbers: true }]]
: [remarkGfm, remarkComment];
Expand All @@ -23,6 +24,7 @@ function getPlugins(config: OutputConfig) {
if (config?.experimentalMath) {
//@ts-ignore
remarkPlugins.push(remarkMath);
//@ts-ignore
rehypePlugins.push(rehypeKatex);
}
return { remarkPlugins, rehypePlugins };
Expand Down
18 changes: 16 additions & 2 deletions api/src/bundler/plugins/rehype-code-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { visit } from 'unist-util-visit';
import { Node } from 'hast-util-heading-rank';
import { toString } from 'mdast-util-to-string';
import * as shiki from 'shiki';

let highlighter: shiki.Highlighter;

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

const raw = toString(node);

if (language === 'mermaid') {
Object.assign(parent, {
type: 'mdxJsxFlowElement',
name: 'Mermaid',
attributes: [
{
type: 'mdxJsxAttribute',
name: 'chart',
value: node.children[0].value,
},
],
});
return;
}

// If the user provides the `console` language, we add the 'shell' language and remove $ from the raw code, for copying purposes.
if (language === 'console') {
const removedDollarSymbol = raw.replace(/^(^ *)\$/g, '');
Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"devDependencies": {
"@types/node-fetch": "^2.6.2",
"@types/pino-std-serializers": "^4.0.0",
"esbuild": "^0.14.47",
"typescript": "^4.5.4"
},
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const config: PlaywrightTestConfig = {
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
timeout: 5000,
},
/* Run tests in files in parallel */
fullyParallel: true,
Expand Down Expand Up @@ -49,7 +49,7 @@ const config: PlaywrightTestConfig = {
use: {
...devices['Desktop Chrome'],
},
}
},

/* Test against mobile viewports. */
// {
Expand Down
6 changes: 6 additions & 0 deletions website/app/components/mdx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Pre } from './Pre';
import { Tabs, TabItem } from './Tabs';
import { Vimeo } from './Vimeo';
import { Tweet } from './Tweet';
import { Mermaid } from 'mdx-mermaid/lib/Mermaid';

function Anchor(
props: DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>,
Expand Down Expand Up @@ -72,4 +73,9 @@ export default {
TabItem,
Tweet,
Vimeo,
Mermaid: ({ chart }: { chart: string }) => {
console.log('here', chart);

return <Mermaid chart={chart} />;
},
};
2 changes: 1 addition & 1 deletion website/app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ hydrateRoot(
<BrowserRouter>
<RemixBrowser />
</BrowserRouter>,
);
);
2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"detect-browser": "^5.3.0",
"express": "^4.18.1",
"lodash.get": "^4.4.2",
"mdx-mermaid": "^v1.3.0",
"mermaid": "^9.1.7",
"morgan": "^1.10.0",
"nprogress": "^0.2.0",
"react": "^18.2.0",
Expand Down
Loading

0 comments on commit 8d2f127

Please sign in to comment.