2023-08-11 15:51:20 +01:00
|
|
|
using Markdig;
|
2023-08-08 21:03:41 +01:00
|
|
|
using Markdig.Renderers;
|
2023-08-13 17:33:54 +01:00
|
|
|
using OliverBooth.Services;
|
2023-08-08 21:03:41 +01:00
|
|
|
|
2023-08-13 17:33:54 +01:00
|
|
|
namespace OliverBooth.Markdown.Template;
|
2023-08-08 21:03:41 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a Markdown extension that adds support for MediaWiki-style templates.
|
|
|
|
/// </summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
public sealed class TemplateExtension : IMarkdownExtension
|
2023-08-08 21:03:41 +01:00
|
|
|
{
|
2023-08-13 13:27:44 +01:00
|
|
|
private readonly ITemplateService _templateService;
|
2023-08-08 21:03:41 +01:00
|
|
|
|
2023-08-09 21:09:32 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TemplateExtension" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="templateService">The template service.</param>
|
2023-08-13 13:27:44 +01:00
|
|
|
public TemplateExtension(ITemplateService templateService)
|
2023-08-08 21:03:41 +01:00
|
|
|
{
|
|
|
|
_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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|