Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-r1-0528· DeepSeekHugging Face LMArena Human Preference 140K

Suggest best way to convert on Linux mermaid diagrams to the dot and svg

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with chatgpt-4o-latest-20250326’s answer.
  1. User

    Suggest best way to convert on Linux mermaid diagrams to the dot and svg

  2. DeepSeek Assistant

    To convert Mermaid diagrams to DOT (Graphviz) and SVG formats on Linux, follow these optimized methods using command-line tools:

    1. Mermaid to SVG (Direct Conversion)

    Use the official Mermaid CLI (mmdc) for reliable SVG generation:

    npm install -g @mermaid-js/mermaid-cli  # Install Mermaid CLI
    mmdc -i input.mmd -o output.svg         # Convert Mermaid to SVG
    

    2. Mermaid to DOT (Graphviz)

    While no direct tool exists for all diagram types, use these approaches:

    A. Flowcharts Only (Using Node.js Script)

    1. Save this script as mermaid2dot.js:

      const mermaid = require('mermaid');
      const { write: toDot } = require('graphlib-dot');
      const fs = require('fs');
      
      const input = fs.readFileSync(process.argv[2], 'utf8');
      mermaid.initialize({ startOnLoad: false });
      const diagram = mermaid.mermaidAPI.getDiagramFromText(input);
      const graph = diagram.parser.yy.getGraph();
      fs.writeFileSync(process.argv[3], toDot(graph));
      
    2. Install dependencies and run:

      npm install mermaid graphlib graphlib-dot
      node mermaid2dot.js input.mmd output.dot
      

      Note: Only supports flowcharts. Tested with Mermaid v10+.

    B. General Diagrams (via PlantUML Intermediate)

    Convert Mermaid → PlantUML → DOT:

    # Install dependencies
    npm install -g @mermaid-js/mermaid-cli
    sudo apt-get install plantuml default-jre  # Or use PlantUML's JAR
    
    # Convert Mermaid to PlantUML
    mmdc -i input.mmd -o intermediate.puml
    
    # Convert PlantUML to DOT
    plantuml -Tdot intermediate.puml -o output.dot
    

    Limitations: PlantUML conversion supports flowcharts and sequence diagrams best.


    3. Dockerized Conversion (No Local Installs)

    Use Docker containers to avoid environment setup:

    # Mermaid to SVG
    docker run -v $(pwd):/data minlag/mermaid-cli -i /data/input.mmd -o /data/output.svg
    
    # Mermaid to DOT (via intermediate formats in a container)
    docker run -v $(pwd):/data plantuml/plantuml -Tdot /data/intermediate.puml -o /data
    

    Workflow Summary

    StepToolCommand
    1aMermaid CLI (SVG)mmdc -i input.mmd -o output.svg
    1bNode.js (DOT)node mermaid2dot.js input.mmd output.dot
    2PlantUML (Intermediate)plantuml -Tdot input.puml -o out.dot
    3Docker (All-in-one)Use minlag/mermaid-cli or plantuml/plantuml images

    Notes & Tips

    • Mermaid CLI: Best for SVG. Supports PNG/PDF via -o output.png/pdf.
    • DOT Conversion:
      • Use the Node.js method for flowcharts.
      • Use PlantUML for sequence diagrams and basic charts.
    • Debugging: Add --backgroundColor transparent to mmdc for transparent SVGs.
    • Complex Diagrams: Some Mermaid features (e.g., Gantt charts) lack DOT support. Use SVG as the primary output.

    For full automation, wrap steps in a shell script. Example:

    #!/bin/bash
    # Convert Mermaid to SVG and DOT
    mmdc -i "$1" -o "${1%.*}.svg"  # SVG output
    node mermaid2dot.js "$1" "${1%.*}.dot"  # DOT for flowcharts
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.