Skip to content

[FEATURE] Render Mermaid diagrams in chat responses #1497

Open

Description

@nicho2

Summary

Add native Mermaid rendering in SurfSense chat responses when the assistant outputs Markdown code blocks tagged as mermaid.

Problem

Currently, Mermaid blocks are displayed as raw code instead of rendered diagrams, which reduces readability for workflows, architectures, sequence diagrams, and technical explanations.

Expected behavior

When the chat response contains:

flowchart TD
    A[User question] --> B[Search sources]
    B --> C[LLM answer]
    C --> D[Display with citations]
Loading

SurfSense should render it as a visual diagram directly in the chat.

Suggested behavior

  • Detect Markdown blocks tagged with mermaid
  • Render valid Mermaid diagrams in the chat UI
  • Keep a fallback to raw code if rendering fails
  • Add a “Copy source” button
  • Ensure safe rendering to avoid XSS/security issues
  • Support light/dark theme if applicable

Value

This would improve technical documentation, architecture explanations, process mapping, and AI-generated visual summaries inside SurfSense.

Activity

  1. added 2 commits that reference this issue on Jun 23, 2026
  2. Cedric921 commented on Oct 17, 2026

    @Cedric921
    Contributor

    I would like to take this for the desktop app. #1534 added Mermaid to surfsense_web, but surfsense_local chat replies and Studio documents still show a mermaid block as code. Since this is a new feature, I will start with a proposal PR in docs/proposals/, as AGENTS.md asks.

    The proposal: render through @streamdown/mermaid, beside the existing code and math plugins in streamdown-config.ts. Diagrams render only once a reply has finished streaming, the same way code highlighting waits. Mermaid loads in its own lazily loaded chunk, so it does not add to startup. It uses securityLevel: strict and follows the app's light and dark theme. An invalid diagram falls back to the code block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions