import { UntitledResourceResolver } from '@theia/core'; import { OpenerService } from '@theia/core/lib/browser'; import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; import { ThemeService } from '@theia/core/lib/browser/theming'; import { ThemeMode } from '@theia/core/lib/common/theme'; import * as React from '@theia/core/shared/react'; import { IMouseEvent } from '@theia/monaco-editor-core'; import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider'; /** * Sanitizes the SVG produced by mermaid before it is injected via `dangerouslySetInnerHTML`. * * Mermaid renders node labels as HTML inside SVG ``, which DOMPurify strips by default. We allow * `foreignObject` and mark it as an HTML integration point so the labels survive while still being sanitized. * DOMPurify removes scripts, event handlers and `javascript:` URLs, but not resource loading, so the hooks below * additionally strip any attribute or CSS reference (`url(...)`, `@import`, `image-set(...)`) that would fetch a * remote resource (an image-based exfiltration vector), while keeping inline `data:` resources, internal * `url(#...)` references and `` links. * Mermaid additionally runs with `securityLevel: 'strict'`. */ export declare const sanitizeDiagram: (svg: string) => string; export interface MermaidDiagramProps { /** The raw mermaid diagram definition. */ code: string; /** Workbench theme mode the diagram is themed for. */ themeMode: ThemeMode; /** Whether the surrounding content is complete. While incomplete, an unparseable diagram shows a "rendering" hint. */ isComplete: boolean; } /** * Renders a mermaid diagram definition into a sanitized, themed SVG. While the definition cannot be parsed and the * content is still incomplete (e.g. streaming) it shows a "rendering" hint. Once complete, an unparseable definition * shows an error placeholder. The SVG is sanitized via {@link sanitizeDiagram}. * * The {@link MermaidViewer} keeps this component mounted across collapse and source toggles, so it renders the * (relatively expensive) diagram only when the definition or theme actually changes, not on every toggle. */ export declare const MermaidDiagram: React.FC; /** Tracks the workbench theme mode (light/dark), re-rendering the consumer when the color theme changes. */ export declare const useThemeMode: (themeService: ThemeService) => ThemeMode; export interface MarkdownMermaidSegment { type: 'markdown' | 'mermaid'; content: string; } /** * Splits markdown text into ```mermaid fenced-code blocks and the (markdown) text around them. * Only mermaid fences are separated out. Every other construct - including non-mermaid code fences - * stays within the surrounding markdown segments so it keeps rendering as before. */ export declare const splitMermaidSegments: (text: string) => MarkdownMermaidSegment[]; export interface MermaidViewerProps { /** The raw mermaid diagram definition. */ code: string; /** Whether the surrounding content is complete. While incomplete, an unparseable diagram shows a "rendering" hint. */ isComplete: boolean; themeService: ThemeService; clipboardService: ClipboardService; editorProvider: MonacoEditorProvider; untitledResourceResolver: UntitledResourceResolver; /** Optional context menu handler for the source view's editor. */ contextMenuCallback?: (event: IMouseEvent) => void; } /** * A self-contained, reusable mermaid viewer: a toolbar (collapse, diagram/source toggle, zoom, copy), a pan/zoom * viewport with the diagram, and the {@link CodeWrapper} editor as the source view. It is not tied to the chat and * can be embedded anywhere a mermaid diagram should be shown. */ export declare const MermaidViewer: React.FC; export interface MarkdownWithMermaidProps { content: string; openerService: OpenerService; themeService: ThemeService; clipboardService: ClipboardService; editorProvider: MonacoEditorProvider; untitledResourceResolver: UntitledResourceResolver; } /** * Renders markdown that may contain ```mermaid fenced blocks, drawing those blocks as diagrams. * * The main chat response splits mermaid blocks into their own content parts (via `parseContents`) which the * `MermaidPartRenderer` then handles. Other surfaces - such as the user interaction tool - instead render a raw * markdown string directly (via `useMarkdownRendering`) and never pass through that pipeline, so a mermaid block * would show as plain code. This component bridges the gap by rendering mermaid blocks with the exact same * {@link MermaidViewer} component used in the chat (so the diagram looks and behaves identically everywhere), while * leaving all other content to normal markdown rendering. */ export declare const MarkdownWithMermaid: React.FC; //# sourceMappingURL=mermaid-rendering.d.ts.map