using Markdig; using Microsoft.Extensions.DependencyInjection; using SmartFormat.Core.Extensions; namespace OliverBooth.Extensions.SmartFormat; /// /// Represents a SmartFormat formatter that formats markdown. /// public sealed class MarkdownFormatter : IFormatter { private readonly IServiceProvider _serviceProvider; /// /// Initializes a new instance of the class. /// /// The . public MarkdownFormatter(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } /// public bool CanAutoDetect { get; set; } = true; /// public string Name { get; set; } = "markdown"; /// public bool TryEvaluateFormat(IFormattingInfo formattingInfo) { if (formattingInfo.CurrentValue is not string value) return false; var pipeline = _serviceProvider.GetService(); formattingInfo.Write(Markdown.ToHtml(value, pipeline)); return true; } }