mermaidpolyglotdotnet-interactive

Display Mermaid diagram from C# variable in Polyglot notebook


I know that Polyglot notebooks support Mermaid diagrams. But it doesn't support veriable sharing. Suppose I have diagram code in C# string variable. Are there any possibility to display that string as diagram?

Example:

// below diagram code was generated via some method
var mermaidCode = """
flowchart TD
    A --> B
""";

// here I would like to display mermaidCode as diagram
mermaidCode

Solution

  • Here is a way that generates a Mermaid output cell by means of a MermaidMarkdown display object:

    #r "Microsoft.DotNet.Interactive.Mermaid.dll"
    using Microsoft.DotNet.Interactive.Mermaid;
    
    var mermaidCode = """
    flowchart TD
        A --> B
    """;
    
    new MermaidMarkdown(mermaidCode)
    

    polyglot notebook screenshot