Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: refine Mermaid diagram presentation

tianma-if9b44e3689e6d
diff --git a/apps/mobile/app.json b/apps/mobile/app.json
index 89b03939..37855bdb 100644
--- a/apps/mobile/app.json
+++ b/apps/mobile/app.json
@@ -3,7 +3,7 @@
"name": "EdgeEver",
"slug": "edgeever",
"scheme": "edgeever",
- "version": "1.5.0",
+ "version": "1.5.1",
"runtimeVersion": {
"policy": "appVersion"
},
@@ -28,7 +28,7 @@
},
"android": {
"package": "org.edgeever.mobile",
- "versionCode": 33,
+ "versionCode": 34,
"adaptiveIcon": {
"backgroundColor": "#d1fae5",
"backgroundImage": "./assets/icon.png",
diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsx
index f072d552..d931f9dc 100644
--- a/apps/mobile/src/components/LocalTiptapEditor.tsx
+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx
@@ -104,7 +104,8 @@ const MermaidRenderRuntime = (props: MermaidRendererProps) => {
startOnLoad: false,
securityLevel: "strict",
suppressErrorRendering: true,
- theme: props.theme === "dark" ? "dark" : "neutral",
+ theme: "base",
+ themeVariables: getMobileMermaidThemeVariables(props.theme),
flowchart: { htmlLabels: false },
});
@@ -748,6 +749,27 @@ const applyImageWidth = (
let mermaidRenderSequence = 0;
+const getMobileMermaidThemeVariables = (theme: "light" | "dark") => {
+ const ink = theme === "dark" ? "#cbd5e1" : "#26384a";
+ const surface = theme === "dark" ? "#0f172a" : "#ffffff";
+ return {
+ background: "transparent",
+ primaryColor: surface,
+ primaryTextColor: ink,
+ primaryBorderColor: ink,
+ lineColor: ink,
+ textColor: ink,
+ mainBkg: surface,
+ nodeBorder: ink,
+ edgeLabelBackground: surface,
+ actorBkg: surface,
+ actorBorder: ink,
+ actorTextColor: ink,
+ signalColor: ink,
+ signalTextColor: ink,
+ };
+};
+
const loadMermaid = () => {
const mermaid = (globalThis as typeof globalThis & {
mermaid?: typeof import("mermaid")["default"];
@@ -772,6 +794,15 @@ const createMobileCodeBlockExtension = (
const code = document.createElement("code");
preview.contentEditable = "false";
preview.className = "edgeever-mermaid-preview";
+ preview.tabIndex = 0;
+ preview.setAttribute("role", "button");
+ preview.addEventListener("click", () => wrapper.classList.toggle("is-source-visible"));
+ preview.addEventListener("keydown", (event) => {
+ if (event.key === "Enter" || event.key === " ") {
+ event.preventDefault();
+ wrapper.classList.toggle("is-source-visible");
+ }
+ });
message.className = "edgeever-mermaid-message";
svgContainer.className = "edgeever-mermaid-svg";
svgContainer.setAttribute("role", "img");
@@ -827,7 +858,8 @@ const createMobileCodeBlockExtension = (
startOnLoad: false,
securityLevel: "strict",
suppressErrorRendering: true,
- theme: theme === "dark" ? "dark" : "neutral",
+ theme: "base",
+ themeVariables: getMobileMermaidThemeVariables(theme),
});
const valid = await mermaid.parse(source, { suppressErrors: true });
if (!valid) {
@@ -1275,12 +1307,13 @@ const getEditorStyles = (theme: "light" | "dark") => `
.edgeever-editor-content pre { overflow-x: auto; border-radius: 10px; padding: 14px; background: #0f172a; color: #e2e8f0; }
.edgeever-editor-content code { border-radius: 4px; padding: 2px 4px; background: ${theme === "dark" ? "#1e293b" : "#f1f5f9"}; }
.edgeever-editor-content pre code { padding: 0; background: transparent; }
- .edgeever-mermaid-code-block { margin: 18px 0; overflow: hidden; border: 1px solid ${theme === "dark" ? "#334155" : "#e2e8f0"}; border-radius: 12px; background: ${theme === "dark" ? "#111827" : "#fff"}; }
- .edgeever-mermaid-code-block > pre { margin: 0; border-radius: 0; border-top: 1px solid ${theme === "dark" ? "#334155" : "#e2e8f0"}; }
- .edgeever-mermaid-preview { display: flex; min-height: 116px; align-items: center; justify-content: center; overflow-x: auto; padding: 14px; background: ${theme === "dark" ? "#0f172a" : "#fff"}; }
+ .edgeever-mermaid-code-block { margin: 18px 0; overflow: visible; background: transparent; }
+ .edgeever-mermaid-code-block > pre { display: none; margin: 8px 0 0; }
+ .edgeever-mermaid-code-block.is-source-visible > pre { display: block; }
+ .edgeever-mermaid-preview { display: flex; min-height: 104px; align-items: center; justify-content: center; overflow-x: auto; padding: 16px 4px; background: transparent; }
.edgeever-mermaid-preview[hidden] { display: none; }
.edgeever-mermaid-svg { width: 100%; text-align: center; }
- .edgeever-mermaid-svg svg { display: block; width: 100%; max-width: 100%; height: auto; max-height: 420px; margin: auto; }
+ .edgeever-mermaid-svg svg { display: block; width: auto; max-width: 100%; height: auto; max-height: 440px; margin: auto; }
.edgeever-mermaid-message, .edgeever-mermaid-error { margin: 0; font-size: 14px; line-height: 1.5; text-align: center; }
.edgeever-mermaid-message { color: ${theme === "dark" ? "#94a3b8" : "#64748b"}; }
.edgeever-mermaid-error { color: ${theme === "dark" ? "#fda4af" : "#be123c"}; }
diff --git a/apps/mobile/src/components/MobileMermaid.tsx b/apps/mobile/src/components/MobileMermaid.tsx
index 69787bb6..55919055 100644
--- a/apps/mobile/src/components/MobileMermaid.tsx
+++ b/apps/mobile/src/components/MobileMermaid.tsx
@@ -107,8 +107,8 @@ export const MobileMermaidDiagram = ({
}
const aspectRatio = getMermaidSvgAspectRatio(svg);
- const availableWidth = Math.max(1, width - 48);
- const height = Math.min(420, Math.max(120, availableWidth / aspectRatio));
+ const availableWidth = Math.max(1, width - 32);
+ const height = Math.min(440, Math.max(120, availableWidth / aspectRatio));
return (
<View accessibilityLabel={locale === "en-US" ? "Mermaid diagram" : "Mermaid 图表"} accessible style={[styles.diagram, theme === "dark" && styles.diagramDark, { height }]}>
<SvgXml height="100%" width="100%" xml={svg} />
@@ -119,16 +119,11 @@ export const MobileMermaidDiagram = ({
const styles = StyleSheet.create({
diagram: {
width: "100%",
- marginVertical: 12,
- borderWidth: 1,
- borderColor: "#e2e8f0",
- borderRadius: 12,
- padding: 10,
- backgroundColor: "#ffffff",
+ marginVertical: 14,
+ backgroundColor: "transparent",
},
diagramDark: {
- borderColor: "#334155",
- backgroundColor: "#0f172a",
+ backgroundColor: "transparent",
},
error: {
marginVertical: 10,
diff --git a/apps/web/src/components/MermaidCodeBlock.tsx b/apps/web/src/components/MermaidCodeBlock.tsx
index f55c173a..e1799415 100644
--- a/apps/web/src/components/MermaidCodeBlock.tsx
+++ b/apps/web/src/components/MermaidCodeBlock.tsx
@@ -10,13 +10,6 @@ let mermaidRenderSequence = 0;
const loadMermaid = () => {
if (!mermaidModulePromise) {
mermaidModulePromise = import("mermaid").then(({ default: mermaid }) => {
- mermaid.initialize({
- startOnLoad: false,
- securityLevel: "strict",
- suppressErrorRendering: true,
- theme: "neutral",
- });
-
return mermaid;
});
}
@@ -30,6 +23,7 @@ export const MermaidCodeBlock = ({ editor, node }: NodeViewProps) => {
const source = node.textContent.trim();
const isMermaid = language === "mermaid";
const [svg, setSvg] = useState("");
+ const [sourceVisible, setSourceVisible] = useState(false);
const [renderState, setRenderState] = useState<"idle" | "loading" | "ready" | "error">("idle");
useEffect(() => {
@@ -45,6 +39,31 @@ export const MermaidCodeBlock = ({ editor, node }: NodeViewProps) => {
void loadMermaid()
.then(async (mermaid) => {
+ const dark = document.documentElement.classList.contains("dark");
+ const ink = dark ? "#cbd5e1" : "#26384a";
+ const surface = dark ? "#0f172a" : "#ffffff";
+ mermaid.initialize({
+ startOnLoad: false,
+ securityLevel: "strict",
+ suppressErrorRendering: true,
+ theme: "base",
+ themeVariables: {
+ background: "transparent",
+ primaryColor: surface,
+ primaryTextColor: ink,
+ primaryBorderColor: ink,
+ lineColor: ink,
+ textColor: ink,
+ mainBkg: surface,
+ nodeBorder: ink,
+ edgeLabelBackground: surface,
+ actorBkg: surface,
+ actorBorder: ink,
+ actorTextColor: ink,
+ signalColor: ink,
+ signalTextColor: ink,
+ },
+ });
const valid = await mermaid.parse(source, { suppressErrors: true });
if (!valid) {
throw new Error("Invalid Mermaid diagram");
@@ -75,11 +94,28 @@ export const MermaidCodeBlock = ({ editor, node }: NodeViewProps) => {
return (
<NodeViewWrapper
- className={isMermaid ? "edgeever-mermaid-code-block" : "edgeever-code-block"}
+ className={isMermaid
+ ? `edgeever-mermaid-code-block${sourceVisible ? " is-source-visible" : ""}`
+ : "edgeever-code-block"}
data-language={language}
>
{isMermaid && (
- <div className="edgeever-mermaid-preview" contentEditable={false}>
+ <div
+ className="edgeever-mermaid-preview"
+ contentEditable={false}
+ onClick={() => editor.isEditable && setSourceVisible((visible) => !visible)}
+ onKeyDown={(event) => {
+ if (editor.isEditable && (event.key === "Enter" || event.key === " ")) {
+ event.preventDefault();
+ setSourceVisible((visible) => !visible);
+ }
+ }}
+ aria-label={editor.isEditable
+ ? `${t("editorToolbar.mermaidPreview")} · ${t("editorToolbar.mermaidSource")}`
+ : undefined}
+ role={editor.isEditable ? "button" : undefined}
+ tabIndex={editor.isEditable ? 0 : undefined}
+ >
{!source && <p className="edgeever-mermaid-message">{t("editorToolbar.mermaidEmpty")}</p>}
{source && renderState === "loading" && !svg && (
<p className="edgeever-mermaid-message">{t("editorToolbar.mermaidRendering")}</p>
diff --git a/apps/web/src/components/MobileStandaloneTiptapEditor.tsx b/apps/web/src/components/MobileStandaloneTiptapEditor.tsx
index d4490ee3..5db1a746 100644
--- a/apps/web/src/components/MobileStandaloneTiptapEditor.tsx
+++ b/apps/web/src/components/MobileStandaloneTiptapEditor.tsx
@@ -39,7 +39,7 @@ import {
type MobileEditorSaveState,
} from "@/lib/mobile-editor-standalone";
import { getMemoUpdateQueueId, isMemoUpdateAlreadyApplied, queueMemoUpdate, shouldQueueMemoSaveError } from "@/lib/sync-queue";
-import { EdgeEverCodeBlock } from "@/lib/code-block";
+import { EdgeEverCodeBlock, codeBlockLowlight } from "@/lib/code-block";
type ListNotebooksResponse = {
notebooks: Notebook[];
@@ -169,7 +169,7 @@ export const MobileStandaloneTiptapEditor = ({
const editor = useEditor({
extensions: [
StarterKit.configure({ codeBlock: false }),
- EdgeEverCodeBlock,
+ EdgeEverCodeBlock.configure({ lowlight: codeBlockLowlight, defaultLanguage: "plaintext" }),
Image.configure({
allowBase64: false,
inline: false,
diff --git a/apps/web/src/mobile-edit.tsx b/apps/web/src/mobile-edit.tsx
index b28e2b06..b8dac38c 100644
--- a/apps/web/src/mobile-edit.tsx
+++ b/apps/web/src/mobile-edit.tsx
@@ -2,6 +2,7 @@ import React from "react";
import { createRoot } from "react-dom/client";
import { MobileStandaloneTiptapEditor } from "@/components/MobileStandaloneTiptapEditor";
import { initializeTheme } from "@/components/ThemeProvider";
+import "./i18n";
import "./styles/mobile-markdown-editor.css";
const root = document.getElementById("mobile-editor-root");
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index 367d2a06..dad86646 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -279,20 +279,19 @@ textarea {
}
.ProseMirror .edgeever-mermaid-code-block {
- overflow: hidden;
- border: 1px solid #d9eadf;
- border-radius: 10px;
- background: #fff;
+ overflow: visible;
+ background: transparent;
}
.ProseMirror .edgeever-mermaid-preview {
display: flex;
- min-height: 8rem;
+ min-height: 6rem;
align-items: center;
justify-content: center;
overflow-x: auto;
- padding: 1rem;
- background: #fff;
+ padding: 1.25rem 0.5rem;
+ background: transparent;
+ cursor: pointer;
}
.ProseMirror .edgeever-mermaid-message,
@@ -314,14 +313,19 @@ textarea {
.ProseMirror .edgeever-mermaid-svg svg {
display: block;
+ width: auto;
max-width: 100%;
height: auto;
+ max-height: 30rem;
}
.ProseMirror .edgeever-mermaid-source {
- border: 0;
- border-top: 1px solid #d9eadf;
- border-radius: 0;
+ display: none;
+ margin-top: 0.5rem;
+}
+
+.ProseMirror .edgeever-mermaid-code-block.is-source-visible .edgeever-mermaid-source {
+ display: block;
}
/* Highlight.js-compatible token classes emitted by Tiptap/lowlight. */
@@ -867,8 +871,7 @@ textarea {
}
:root.dark .ProseMirror .edgeever-mermaid-code-block {
- border-color: #166534;
- background: #13261a;
+ background: transparent;
}
:root.dark .ProseMirror .edgeever-code-source {
@@ -878,11 +881,7 @@ textarea {
}
:root.dark .ProseMirror .edgeever-mermaid-preview {
- background: #f8fafc;
-}
-
-:root.dark .ProseMirror .edgeever-mermaid-source {
- border-top-color: #166534;
+ background: transparent;
}
:root.dark .markdown-content {
diff --git a/apps/web/src/styles/mobile-markdown-editor.css b/apps/web/src/styles/mobile-markdown-editor.css
index 1221500b..57c27881 100644
--- a/apps/web/src/styles/mobile-markdown-editor.css
+++ b/apps/web/src/styles/mobile-markdown-editor.css
@@ -494,6 +494,69 @@ input {
margin: 1.2rem 0;
}
+.edgeever-mobile-tiptap-content .edgeever-code-source {
+ overflow-x: auto;
+ border: 1px solid #d9eadf;
+ border-radius: 8px;
+ background: #f7fbf8;
+ padding: 0.9rem 1rem;
+ color: #1e293b;
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
+ font-size: 0.875em;
+ white-space: pre;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-code-block {
+ margin: 18px 0;
+ overflow: visible;
+ background: transparent;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-preview {
+ display: flex;
+ min-height: 6rem;
+ align-items: center;
+ justify-content: center;
+ overflow-x: auto;
+ padding: 1rem 0.25rem;
+ background: transparent;
+ cursor: pointer;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-svg {
+ display: flex;
+ width: 100%;
+ justify-content: center;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-svg svg {
+ display: block;
+ width: auto;
+ max-width: 100%;
+ height: auto;
+ max-height: 440px;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-source {
+ display: none;
+ margin-top: 0.5rem;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-code-block.is-source-visible .edgeever-mermaid-source {
+ display: block;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-message,
+.edgeever-mobile-tiptap-content .edgeever-mermaid-error {
+ margin: 0;
+ color: #64748b;
+ font-size: 0.82rem;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-error {
+ color: #be123c;
+}
+
.edgeever-mobile-tiptap-content img {
height: auto;
max-width: 100%;
@@ -587,6 +650,12 @@ input {
color: #f8fafc;
}
+:root.dark .edgeever-mobile-tiptap-content .edgeever-code-source {
+ border-color: #166534;
+ background: #13261a;
+ color: #cbd5e1;
+}
+
:root.dark .edgeever-mobile-tiptap-content .tableWrapper {
border-color: #334155;
background: #0f172a;