Hello Mat

 找回密码
 立即注册
查看: 23|回复: 0

mermaid图表生成

[复制链接]

1360

主题

1596

帖子

10

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22837
发表于 3 天前 | 显示全部楼层 |阅读模式
  1. public MermaidForm()
  2.         {
  3.             InitializeComponent();
  4.             webView21.EnsureCoreWebView2Async(null);
  5.         }

  6.         private void MermaidForm_Load(object sender, EventArgs e)
  7.         {

  8.         }

  9.         private async void button1_Click(object sender, EventArgs e)
  10.         {
  11.             string code = richTextBox1.Text.Trim();
  12.             if (string.IsNullOrEmpty(code))
  13.             {
  14.                 MessageBox.Show("请输入Mermaid代码");
  15.                 return;
  16.             }
  17.             if (string.IsNullOrWhiteSpace(code))
  18.             {
  19.                 MessageBox.Show("请输入Mermaid代码");
  20.                 return;
  21.             }

  22.             // 本地JS文件路径(exe同目录)
  23.             string jsPath = Path.Combine(Application.StartupPath, "mermaid.min.js");
  24.             string jsWebPath = "file:///" + jsPath.Replace("\", "/");
  25.             // HTML 离线模板
  26.             string safeCode = code.Replace(""", """).Replace("'", "'");

  27.             string html = $@"
  28. <!DOCTYPE html>
  29. <html>
  30. <head>
  31.     <meta charset=""utf-8"">
  32.     <script src=""{jsWebPath}""></script>
  33. </head>
  34. <body style=""background:white;padding:20px"">
  35.     <div class=""mermaid"">{safeCode}</div>

  36.     <script>
  37.         mermaid.initialize({{
  38.             startOnLoad: true,
  39.             theme: 'default'
  40.         }});
  41.     </script>
  42. </body>
  43. </html>";
  44.             // 加载渲染
  45.             //await webView21.CoreWebView2.NavigateToString(html);
  46.             webView21.NavigateToString(html);
  47.         }
复制代码


算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2026-5-10 07:35 , Processed in 0.217492 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表