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/MarkdownToHtml.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 Nitride.Contents;
using Nitride.Html;
namespace Nitride.Markdown
{
/// <summary>
/// Converts the input Markdown files into HTML using Markdig. This only
/// processes files with a text input and the IsMarkdown component.
/// </summary>
public class MarkdownToHtml : 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)
{
// 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<IsMarkdown>()
.Set(IsHtml.Instance);
// Return the resulting entity.
return entity;
}
}
}