Archive Browser
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.Helpers;
using Markdig.Renderers;
using Markdig.Renderers.Html;
namespace MarkdigMantisLink
{
public class MantisLinkRenderer : HtmlObjectRenderer<MantisLink>
{
#region Fields
private MantisLinkOptions _options;
#endregion
#region Constructors
public MantisLinkRenderer(MantisLinkOptions options)
{
_options = options;
}
#endregion
#region Properties
public MantisLinkOptions Options
{
get { return _options; }
set { _options = value; }
}
#endregion
#region Methods
protected override void Write(HtmlRenderer renderer, MantisLink obj)
{
StringSlice issueNumber;
issueNumber = obj.IssueNumber;
if (renderer.EnableHtmlForInline)
{
// write a full a tag
renderer.Write("<a href=\"").Write(_options.Url).Write("view.php?id=").Write(issueNumber).Write('"');
if (_options.OpenInNewWindow)
{
// if adding the `target` attribute, also add a `rel` as per MDN
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target
renderer.Write(" target=\"blank\" rel=\"noopener noreferrer\"");
}
renderer.Write('>').Write('#').Write(issueNumber).Write("</a>");
}
else
{
// inline HTML is disabled, so write the raw value
renderer.Write('#').Write(obj.IssueNumber);
}
}
#endregion
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate