Created
September 22, 2025 21:26
-
-
Save otac0n/0dd8ac5c4589a51b82ba341df7240e3f to your computer and use it in GitHub Desktop.
Adds mermaid chart rendering to LINQPad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Adapted from https://forum.linqpad.net/discussion/2803/can-not-render-mermaidjs-on-result-panel | |
| public static class MermaidUtil | |
| { | |
| public static LINQPad.Controls.Control Render(string chartSource) => new MermaidInstance(chartSource); | |
| private class MermaidInstance : LINQPad.Controls.Control | |
| { | |
| public MermaidInstance(string src) : base("pre") | |
| { | |
| this.CssClass = $"mermaid"; | |
| this.HtmlElement.InnerHtml = src; | |
| this.HtmlElement.ID = Guid.NewGuid().ToString("N"); | |
| } | |
| protected override void OnRendering(EventArgs e) | |
| { | |
| Util.HtmlHead.AddScriptFromUri("https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"); | |
| base.OnRendering(e); | |
| Util.RawHtml($$""" | |
| <script type="text/javascript"> | |
| setTimeout(function () { | |
| mermaid.run({ nodes: [ document.getElementById('{{this.HtmlElement.ID}}') ] }); | |
| }, 10); | |
| </script> | |
| """).Dump(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment