oliverbooth.dev/OliverBooth/Markdown/Template/TemplateExtension.cs
Oliver Booth 0a9c2e82d5
refactor: combine sites into one
CORS was "cors"ing some issues (heh).

But also it is easier to maintain this way. Development was made much more difficult when I separated it. Combining it all also improves SEO
2023-08-13 17:34:38 +01:00

38 lines
1.1 KiB
C#

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;
/// <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));
}
}
}