52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
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();
|
|
}
|
|
}
|