using System;
using FluentValidation;
using MfGames.Gallium;
using Markdig;
using MfGames.Markdown.Gemtext;
using MfGames.Nitride.Contents;
using MfGames.Nitride.Gemtext;
namespace MfGames.Nitride.Markdown;
///
/// Converts the input Markdown files into Gemtext using Markdig and
/// MfGames.Markdown.Gemtext. This only processes files with a text input
/// and the IsMarkdown component.
///
public class ConvertMarkdownToGemtext : ConvertMarkdownToBase
{
public ConvertMarkdownToGemtext(IValidator validator)
: base(validator)
{
}
///
public override ConvertMarkdownToGemtext 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)
{
string markdown = markdownContent.GetText();
string gemtext = MarkdownGemtext.ToGemtext(markdown, options);
var content = new StringTextContent(gemtext);
entity = entity.SetTextContent(content)
.Remove()
.Set(IsGemtext.Instance);
return entity;
}
}