Skip to content

Commit cf2dca0

Browse files
committed
feat(dory): change {variables} to be styled and fix mermaid styles
1 parent 123ab83 commit cf2dca0

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"remark-gfm": "^4.0.1",
3434
"saas": "^1.0.0",
3535
"tailwindcss": "^4.1.8",
36+
"unist-util-visit": "^5.0.0",
3637
"vite-plugin-mdx": "^3.6.1",
3738
"wouter-preact": "^3.7.1"
3839
},

pnpm-lock.yaml

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

src/mdx/mermaid.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ export function MermaidRenderer({ content }: { content: string }) {
4141
mermaidRef.current.innerHTML = ''
4242
}
4343

44-
const contentWithoutStyle = content.replace(/classDef.*\n.*class.*\n/, '')
45-
46-
const { svg } = await mermaid.render(diagramId, contentWithoutStyle)
44+
const contentWithoutStyle = content
45+
.replace(/^\s*style .*$/gm, '')
46+
.replace(/^\s*classDef .*$/gm, '')
47+
.replace(/^\s*class .*$/gm, '');
48+
49+
const { svg } = await mermaid.render(diagramId, contentWithoutStyle);
50+
4751

4852
if (mounted && mermaidRef.current) {
4953
mermaidRef.current.innerHTML = svg

src/plugins/sanitize.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { visit } from 'unist-util-visit';
2+
3+
export const remarkSafeVars = () => {
4+
return (tree: any) => {
5+
visit(tree, 'mdxTextExpression', (node: any, index: number | undefined, parent: any) => {
6+
if (parent && typeof index === 'number') {
7+
// Replace mdxTextExpression with inlineCode node for code formatting
8+
parent.children[index] = {
9+
type: 'inlineCode',
10+
value: node.value
11+
};
12+
}
13+
});
14+
};
15+
};

vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import preact from '@preact/preset-vite';
33
import mdx from '@mdx-js/rollup';
44
import tailwindcss from '@tailwindcss/vite'
55
import remarkGfm from 'remark-gfm';
6+
import { remarkSafeVars } from './src/plugins/sanitize';
67

78
export default defineConfig({
89
plugins: [
910
preact(),
1011
mdx({
1112
providerImportSource: '@mdx-js/preact',
12-
remarkPlugins: [remarkGfm],
13+
remarkPlugins: [remarkGfm, remarkSafeVars],
1314
}),
1415
tailwindcss(),
1516
],

0 commit comments

Comments
 (0)