This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/Nitride.Markdown/MarkdownToGemtext.cs
Dylan R. E. Moonfire 78054ee2a7 feat: initial release
2021-09-07 00:15:45 -05:00

41 lines
1.3 KiB
C#

using Gallium;
using Markdig;
using MfGames.Markdown.Gemtext;
using Nitride.Contents;
using Nitride.Gemtext;
namespace Nitride.Markdown
{
/// <summary>
/// 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.
/// </summary>
public class MarkdownToGemtext : MarkdownOperationBase
{
/// <summary>
/// Converts the Markdown file into HTML.
/// </summary>
/// <param name="entity">The entity to convert.</param>
/// <param name="markdownContent">The content for this entity.</param>
/// <param name="options">The markdown pipeline.</param>
/// <returns>A converted entity.</returns>
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<IsMarkdown>()
.Set(IsGemtext.Instance);
return entity;
}
}
}