@using Markdig
@using Markdig.Renderers.Html
@using Markdig.Syntax
@using Markdig.Syntax.Inlines
@model string
@if (!string.IsNullOrEmpty(Model))
{
var pipeline = new MarkdownPipelineBuilder()
.UseAutoLinks()
.UsePipeTables()
.UseTaskLists()
.UseEmphasisExtras()
.UseAutoIdentifiers()
.Build();
var document = Markdown.Parse(Model, pipeline);
foreach (var link in document.Descendants<LinkInline>())
{
if (Uri.TryCreate(link.Url, UriKind.Absolute, out _))
{
link.GetAttributes().AddPropertyIfNotExist("target", "_blank");
}
else
{
link.Url = Url.Action("Index", new {Path = link.Url});
}
}
foreach (var link in document.Descendants<AutolinkInline>())
{
link.GetAttributes().AddPropertyIfNotExist("target", "_blank");
}
var htmlResult = document.ToHtml(pipeline);
<div class="readme-main">
<div class="readme-content shadow">
<div class="markdown-body">
@Html.Raw(htmlResult)
</div>
</div>
</div>
}