Download MarkdigMantisLink.zip, last updated 05/08/2017 (10.77 KB)

Download
  • md5: 0732dcf3eadac30820596c4fd7bea306
  • sha1: b09fac52bfaac22748f6c8210d197492494614e5
  • sha256: 1dbb16d0bf3c2416992efe83e97ac37b5e886d7c0aa752007d3c8c459afdcdd9
// Copyright (c) 2017 Cyotek Ltd.
// http://www.cyotek.com/blog/writing-custom-markdig-extensions
// Licensed under the MIT License. See LICENSE.txt for the full text.

using Markdig;
using Markdig.Helpers;
using Markdig.Parsers;
using Markdig.Renderers;

namespace MarkdigMantisLink
{
  public class MantisLinkerExtension : IMarkdownExtension
  {
    #region Constants

    private readonly MantisLinkOptions _options;

    #endregion

    #region Constructors

    public MantisLinkerExtension(MantisLinkOptions options)
    {
      _options = options;
    }

    #endregion

    #region IMarkdownExtension Interface

    public void Setup(MarkdownPipelineBuilder pipeline)
    {
      OrderedList<InlineParser> parsers;

      parsers = pipeline.InlineParsers;

      if (!parsers.Contains<MantisLinkInlineParser>())
      {
        parsers.Add(new MantisLinkInlineParser());
      }
    }

    public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
    {
      HtmlRenderer htmlRenderer;
      ObjectRendererCollection renderers;

      htmlRenderer = renderer as HtmlRenderer;
      renderers = htmlRenderer?.ObjectRenderers;

      if (renderers != null && !renderers.Contains<MantisLinkRenderer>())
      {
        renderers.Add(new MantisLinkRenderer(_options));
      }
    }

    #endregion
  }
}

Donate

Donate