using Markdig;
using System.Text.RegularExpressions;
namespace GCBoK.WebStaticBuilder;
/// Markdown processing with Markdig and post-processing.
public static class MarkdownProcessor
{
private static readonly Lazy Pipeline = new(() =>
new MarkdownPipelineBuilder().UseAdvancedExtensions().Build());
public static string RenderMarkdown(string content)
{
var pipeline = Pipeline.Value;
return Markdown.ToHtml(content, pipeline);
}
public static string MermaidPostprocess(string html)
{
var pattern1 = @"(.*?)
";
var regex1 = new Regex(pattern1, RegexOptions.Singleline);
html = regex1.Replace(html, m =>
{
var code = m.Groups[1].Value
.Replace("<", "<").Replace(">", ">").Replace("&", "&");
return $"{code}
";
});
var pattern2 = @"(.*?)
";
var regex2 = new Regex(pattern2, RegexOptions.Singleline);
html = regex2.Replace(html, m =>
{
var code = m.Groups[1].Value
.Replace("<", "<").Replace(">", ">").Replace("&", "&");
return $"{code}
";
});
return html;
}
public static string TablePostprocess(string html)
{
return html.Replace("