Skip to content

Commit 80276c3

Browse files
committed
Merge main into storybook-tool-messages
2 parents e8f73c0 + 1cdd473 commit 80276c3

File tree

11 files changed

+791
-265
lines changed

11 files changed

+791
-265
lines changed

bun.lock

Lines changed: 347 additions & 229 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"main": "dist/main.js",
66
"scripts": {
77
"dev": "bun run build:main && concurrently -k \"bun run dev:main\" \"bun run dev:renderer\"",
8-
"dev:main": "tsc -w -p tsconfig.main.json",
8+
"dev:main": "concurrently \"tsc -w -p tsconfig.main.json\" \"tsc-alias -w -p tsconfig.main.json\"",
99
"dev:renderer": "vite",
1010
"build": "bun run build:renderer && bun run build:main && bun run build:preload",
11-
"build:main": "tsc -p tsconfig.main.json",
11+
"build:main": "tsc -p tsconfig.main.json && tsc-alias -p tsconfig.main.json",
1212
"build:preload": "bun build src/preload.ts --format=cjs --target=node --external=electron --outfile=dist/preload.js",
1313
"build:renderer": "vite build",
1414
"start": "bun build:preload && electron .",
@@ -44,11 +44,14 @@
4444
"diff": "^8.0.2",
4545
"jsonc-parser": "^3.3.1",
4646
"lru-cache": "^11.2.2",
47+
"mermaid": "^11.12.0",
4748
"react": "^18.2.0",
4849
"react-dom": "^18.2.0",
4950
"react-markdown": "^10.1.0",
5051
"react-syntax-highlighter": "^15.6.6",
52+
"rehype-katex": "^7.0.1",
5153
"remark-gfm": "^4.0.1",
54+
"remark-math": "^6.0.0",
5255
"write-file-atomic": "^6.0.0",
5356
"zod": "^4.1.11",
5457
"zod-to-json-schema": "^3.24.6"
@@ -67,6 +70,7 @@
6770
"@types/bun": "^1.2.23",
6871
"@types/diff": "^8.0.0",
6972
"@types/jest": "^30.0.0",
73+
"@types/katex": "^0.16.7",
7074
"@types/react": "^18.2.0",
7175
"@types/react-dom": "^18.2.0",
7276
"@types/react-syntax-highlighter": "^15.5.13",
@@ -88,6 +92,7 @@
8892
"prettier": "^3.6.2",
8993
"storybook": "^9.1.10",
9094
"ts-jest": "^29.4.4",
95+
"tsc-alias": "^1.8.16",
9196
"typescript": "^5.1.3",
9297
"typescript-eslint": "^8.45.0",
9398
"vite": "^4.4.0",

src/components/Messages/MarkdownComponents.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { CSSProperties } from "react";
33
import React from "react";
44
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
55
import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism";
6+
import { Mermaid } from "./Mermaid";
67

78
// Create style with colors only (no backgrounds)
89
const syntaxStyleNoBackgrounds: Record<string, CSSProperties> = {};
@@ -41,11 +42,16 @@ export const markdownComponents = {
4142
const isInline = inline ?? !hasMultipleLines;
4243

4344
if (!isInline && language) {
44-
// Code block with language - use syntax highlighter
4545
// Extract text content from children (react-markdown passes string or array of strings)
4646
const code =
4747
typeof children === "string" ? children : Array.isArray(children) ? children.join("") : "";
4848

49+
// Handle mermaid diagrams
50+
if (language === "mermaid") {
51+
return <Mermaid chart={code} />;
52+
}
53+
54+
// Code block with language - use syntax highlighter
4955
return (
5056
<SyntaxHighlighter
5157
style={syntaxStyleNoBackgrounds}

src/components/Messages/MarkdownCore.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, { useMemo } from "react";
22
import ReactMarkdown from "react-markdown";
33
import remarkGfm from "remark-gfm";
4+
import remarkMath from "remark-math";
5+
import rehypeKatex from "rehype-katex";
6+
import "katex/dist/katex.min.css";
47
import { normalizeMarkdown } from "./MarkdownStyles";
58
import { markdownComponents } from "./MarkdownComponents";
69

@@ -19,7 +22,11 @@ export const MarkdownCore: React.FC<MarkdownCoreProps> = ({ content, children })
1922

2023
return (
2124
<>
22-
<ReactMarkdown components={markdownComponents} remarkPlugins={[remarkGfm]}>
25+
<ReactMarkdown
26+
components={markdownComponents}
27+
remarkPlugins={[remarkGfm, remarkMath]}
28+
rehypePlugins={[rehypeKatex]}
29+
>
2330
{normalizedContent}
2431
</ReactMarkdown>
2532
{children}

src/components/Messages/MarkdownStyles.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,66 @@ export const markdownStyles = css`
149149
text-decoration: line-through;
150150
opacity: 0.6;
151151
}
152+
153+
/* Mermaid diagrams */
154+
.mermaid-container {
155+
display: flex;
156+
justify-content: center;
157+
align-items: center;
158+
overflow-x: auto;
159+
max-width: 100%;
160+
161+
svg {
162+
min-width: min-content;
163+
max-width: none;
164+
max-height: var(--diagram-max-height, 300px);
165+
height: auto;
166+
}
167+
}
168+
169+
/* Mermaid in modal - allow larger sizing */
170+
.mermaid-modal {
171+
svg {
172+
max-width: none;
173+
width: auto;
174+
max-height: 80vh;
175+
}
176+
}
177+
178+
/* Zoom wrapper for mermaid */
179+
.react-transform-wrapper {
180+
position: relative;
181+
width: 100%;
182+
background: rgba(0, 0, 0, 0.2);
183+
border-radius: 4px;
184+
margin: 1em 0;
185+
}
186+
187+
.react-transform-component {
188+
width: 100%;
189+
height: 100%;
190+
}
191+
192+
/* KaTeX math rendering */
193+
.katex {
194+
font-size: 1.1em;
195+
}
196+
197+
.katex-display {
198+
margin: 1em 0;
199+
overflow-x: auto;
200+
overflow-y: hidden;
201+
202+
> .katex {
203+
text-align: center;
204+
}
205+
}
206+
207+
/* Math inline */
208+
p .katex,
209+
li .katex {
210+
display: inline;
211+
}
152212
`;
153213

154214
// Normalize markdown to remove excess blank lines

0 commit comments

Comments
 (0)