using Markdig;
using Markdig.Extensions.Tables;
using Markdig.Parsers.Inlines;
using Markdig.Renderers;
using MfGames.Markdown.Gemtext.Renderers;
using MfGames.Markdown.Gemtext.Renderers.Gemtext.Blocks;
namespace MfGames.Markdown.Gemtext.Extensions
{
///
/// Extension method to control how links are processed inside blocks.
///
///
public class GemtextPipeTableExtension : IMarkdownExtension
{
///
/// Initializes a new instance of the
/// class.
///
/// The options.
public GemtextPipeTableExtension(
GemtextPipeTableOptions? options = null)
{
this.Options = options ?? new GemtextPipeTableOptions();
}
///
/// Gets the options.
///
public GemtextPipeTableOptions Options { get; }
///
public void Setup(MarkdownPipelineBuilder pipeline)
{
pipeline.PreciseSourceLocation = true;
if (!pipeline.BlockParsers.Contains())
{
pipeline.BlockParsers.Insert(0, new PipeTableBlockParser());
}
LineBreakInlineParser? lineBreakParser =
pipeline.InlineParsers.FindExact();
if (!pipeline.InlineParsers.Contains())
{
pipeline.InlineParsers.InsertBefore(
new PipeTableParser(lineBreakParser!, this.Options));
}
}
///
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
{
if (renderer is not GemtextRenderer gemtext)
{
return;
}
gemtext.ObjectRenderers.Add(
new TableRenderer(this.Options.ConfigureTableBuilder));
}
}
}