Skip to content

Add Mermaid diagram support#26

Open
leeguooooo wants to merge 2 commits intodavidgranstrom:masterfrom
leeguooooo:feature/mermaid-support
Open

Add Mermaid diagram support#26
leeguooooo wants to merge 2 commits intodavidgranstrom:masterfrom
leeguooooo:feature/mermaid-support

Conversation

@leeguooooo
Copy link
Copy Markdown

Summary

This PR adds comprehensive support for rendering Mermaid diagrams in markdown preview.

Features

  • ✅ Support for all Mermaid diagram types (flowcharts, sequence diagrams, Gantt charts, etc.)
  • ✅ Handles complex diagrams with emoji, Chinese characters, and special symbols
  • ✅ Automatic HTML entity decoding for proper diagram syntax
  • ✅ Manual initialization for reliable rendering

Implementation Details

  • Added Mermaid JavaScript initialization script (js/mermaid-init.js)
  • Modified Pandoc generation to include Mermaid library and initialization
  • Uses Mermaid CDN v10.6.1 for library loading
  • Configured with appropriate security and rendering settings

Testing

Create a markdown file with mermaid code blocks and run :MarkdownPreview

Simple example:

graph TD
    A[Start] --> B[Process]
    B --> C[End]
Loading

Complex example with emoji and Chinese:

flowchart TB
    subgraph "🌟 核心功能"
        A[⚡ 智能限流] --> A1[IP 分片架构]
        B[🎯 智能缓存] --> B1[版本控制]
    end
    style A fill:#ff9999
    style B fill:#99ccff
Loading

Commits

  • Add Mermaid diagram support
  • Fix Mermaid rendering for complex diagrams

- Add JavaScript initialization for Mermaid rendering
- Include Mermaid script in Pandoc HTML generation
- Support flowcharts, sequence diagrams, Gantt charts and more
- Set startOnLoad to false for manual initialization control
- Add securityLevel loose to support complex content
- Enable manual initialization for dynamically created elements
- Support emoji, Chinese characters, and complex subgraphs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant