48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using Markdig;
|
|
using Markdig.Parsers.Inlines;
|
|
using Markdig.Renderers;
|
|
|
|
namespace MfGames.Markdown.Extensions;
|
|
|
|
/// <summary>
|
|
/// Translate `[[Bob]]` into `/bob/`.
|
|
/// </summary>
|
|
public class WikiLinkExtension : IMarkdownExtension
|
|
{
|
|
public WikiLinkExtension()
|
|
: this(null)
|
|
{
|
|
}
|
|
|
|
public WikiLinkExtension(WikiLinkOptions? options)
|
|
{
|
|
this.Options = options ?? new WikiLinkOptions();
|
|
}
|
|
|
|
public WikiLinkOptions Options { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public void Setup(MarkdownPipelineBuilder pipeline)
|
|
{
|
|
WikiLinkInlineParser? parser = pipeline.InlineParsers
|
|
.FindExact<WikiLinkInlineParser>();
|
|
|
|
if (parser != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
parser = new WikiLinkInlineParser(this.Options);
|
|
pipeline.InlineParsers.InsertBefore<LinkInlineParser>(parser);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Setup(
|
|
MarkdownPipeline pipeline,
|
|
IMarkdownRenderer renderer)
|
|
{
|
|
// No setup needed here because we're using LinkInline which does the
|
|
// bulk of the work.
|
|
}
|
|
}
|