using Markdig;
using SmartFormat.Core.Extensions;
namespace OliverBooth.Formatting;
///
/// 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(Markdig.Markdown.ToHtml(value, pipeline));
return true;
}
}