Добавлены mermaid диаграммы
This commit is contained in:
51
SQLLinter/Infrastructure/Diagram/FragmentDiagramBuilder.cs
Normal file
51
SQLLinter/Infrastructure/Diagram/FragmentDiagramBuilder.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Text;
|
||||
using Microsoft.SqlServer.TransactSql.ScriptDom;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Diagram;
|
||||
|
||||
public static class FragmentDiagramBuilder
|
||||
{
|
||||
public static string RenderMermaid(TSqlFragment fragment)
|
||||
{
|
||||
if (fragment == null) return string.Empty;
|
||||
var diagram = BpmnBuilder.Build(fragment);
|
||||
return MermaidRenderer.RenderMarkdown(diagram);
|
||||
}
|
||||
|
||||
public static string RenderHtmlSvg(TSqlFragment fragment)
|
||||
{
|
||||
if (fragment == null) return string.Empty;
|
||||
var diagram = BpmnBuilder.Build(fragment);
|
||||
// Use mermaid HTML instead of SVG fallback
|
||||
return MermaidRenderer.RenderHtml(diagram);
|
||||
}
|
||||
|
||||
// keep helpers used by earlier code if needed
|
||||
private static string Escape(string s)
|
||||
{
|
||||
if (s == null) return string.Empty;
|
||||
return System.Net.WebUtility.HtmlEncode(s).Replace("\n", " ").Replace("\r", " ");
|
||||
}
|
||||
|
||||
private static string Truncate(string s, int len)
|
||||
{
|
||||
if (s == null) return string.Empty;
|
||||
if (s.Length <= len) return s;
|
||||
return s.Substring(0, len - 3) + "...";
|
||||
}
|
||||
|
||||
private static string SanitizeId(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s)) return "id";
|
||||
var sb = new StringBuilder();
|
||||
foreach (var ch in s)
|
||||
{
|
||||
if (char.IsLetterOrDigit(ch)) sb.Append(ch);
|
||||
else sb.Append('_');
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user