using System; using FluentValidation; using Markdig; using MfGames.Gallium; using MfGames.Nitride.Contents; using MfGames.Nitride.Html; namespace MfGames.Nitride.Markdown; /// /// Converts the input Markdown files into HTML using Markdig. This only /// processes files with a text input and the IsMarkdown component. /// public class ConvertMarkdownToHtml : ConvertMarkdownToBase { public ConvertMarkdownToHtml(IValidator validator) : base(validator) { } /// public override ConvertMarkdownToHtml WithConfigureMarkdown( Action? value) { base.WithConfigureMarkdown(value); return this; } /// /// Converts the Markdown file into HTML. /// /// The entity to convert. /// The content for this entity. /// The markdown pipeline. /// A converted entity. protected override Entity Convert( Entity entity, ITextContent markdownContent, MarkdownPipeline options) { // Convert the entity to Html. string markdown = markdownContent.GetText(); string html = Markdig.Markdown.ToHtml(markdown, options); var htmlContent = new StringTextContent(html); entity = entity.SetTextContent(htmlContent) .Remove() .Set(IsHtml.Instance); // Return the resulting entity. return entity; } }