oliverbooth.dev/OliverBooth/Markdown/Template/TemplateExtension.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2023-08-11 14:51:20 +00:00
using Markdig;
using Markdig.Renderers;
using OliverBooth.Services;
namespace OliverBooth.Markdown.Template;
/// <summary>
/// Represents a Markdown extension that adds support for MediaWiki-style templates.
/// </summary>
public sealed class TemplateExtension : IMarkdownExtension
{
private readonly ITemplateService _templateService;
2023-08-09 20:09:32 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="TemplateExtension" /> class.
/// </summary>
/// <param name="templateService">The template service.</param>
public TemplateExtension(ITemplateService templateService)
{
_templateService = templateService;
}
/// <inheritdoc />
public void Setup(MarkdownPipelineBuilder pipeline)
{
pipeline.InlineParsers.AddIfNotAlready<TemplateInlineParser>();
}
/// <inheritdoc />
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
{
if (renderer is HtmlRenderer htmlRenderer)
{
htmlRenderer.ObjectRenderers.Add(new TemplateRenderer(_templateService));
}
}
}