mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 22:29:07 +00:00
Thorsten Sommer
c84184e5d1
This is necessary due to issue https://github.com/MyNihongo/MudBlazor.Markdown/issues/247 I created a PR as well: https://github.com/MyNihongo/MudBlazor.Markdown/pull/246
45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using Markdig.Helpers;
|
|
using Markdig.Syntax;
|
|
using Markdig.Syntax.Inlines;
|
|
|
|
namespace MudBlazor;
|
|
|
|
internal static class HeadingBlockEx
|
|
{
|
|
private const char JoinChar = '-';
|
|
private static readonly string[] EscapeChars = { "+", ":", "&" };
|
|
|
|
public static string? BuildIdString(this HeadingBlock @this)
|
|
{
|
|
if (@this.Inline == null)
|
|
return null;
|
|
|
|
var slices = @this.Inline
|
|
.Select(static x => x.GetStringContent())
|
|
.Where(static x => x.Length > 0);
|
|
|
|
return string.Join(JoinChar, slices);
|
|
}
|
|
|
|
private static string GetStringContent(this Inline @this)
|
|
{
|
|
var slice = @this switch
|
|
{
|
|
LiteralInline x => x.Content,
|
|
_ => StringSlice.Empty
|
|
};
|
|
|
|
return PrepareStringContent(slice.ToString());
|
|
}
|
|
|
|
private static string PrepareStringContent(this string @this)
|
|
{
|
|
var words = @this.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
|
var str = string.Join(JoinChar, words).ToLower();
|
|
|
|
for (var i = 0; i < EscapeChars.Length; i++)
|
|
str = str.Replace(EscapeChars[i], string.Empty);
|
|
|
|
return str;
|
|
}
|
|
} |