@using Dpz.Core.EnumLibrary
@using Dpz.Core.Infrastructure
@using AngleSharp
@using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration
@model VmMumble
@inject IConfiguration Configuration
@{
var sanitizer = Configuration.CustomHtmlSanitizer();
var context = BrowsingContext.New(AngleSharp.Configuration.Default);
var cdnBaseAddress = Configuration["CDNBaseAddress"];
async Task<string> ClearHtmlAsync(string html)
{
var document = await context.OpenAsync(y => y.Content(html));
var links = document.GetElementsByTagName("a");
links.ForEach(y =>
{
var href = y.GetAttribute("href");
if (href != null && !href.StartsWith("javascript", StringComparison.CurrentCultureIgnoreCase))
{
y.SetAttribute("target", "_blank");
}
});
var images = document.GetElementsByTagName("img");
images.ForEach(y =>
{
var src = y.GetAttribute("src");
y.SetAttribute("data-src", src ?? $"{cdnBaseAddress}/images/notfound.png");
y.SetAttribute("loading", "lazy");
y.SetAttribute("class","lazy");
y.SetAttribute("src", $"{cdnBaseAddress}/loaders/bars.svg");
});
return sanitizer.Sanitize(document.Body?.InnerHtml ?? "");
}
}
<div class="blog-container">
<blockquote class="layui-elem-quote sitemap layui-breadcrumb shadow">
<a href="/" data-pjax title="网站首页">网站首页</a>
<a asp-action="Index" asp-route-pageIndex="1" data-pjax title="网站首页">碎碎念</a>
<a><cite></cite>碎碎念回复</a>
</blockquote>
<div class="mumble-detail">
<div class="mumble-item">
<div class="mumble-item-user">
<div class="mumble-avatar">
<avatar user="Model.Author"></avatar>
</div>
<div class="mumble-info">
<div class="mumble-nickname">
@Model.Author.Name
<span class="identity">@(Model.Author.Permissions?.HasFlag(Permissions.System) == true ? "管理员" : "成员")</span>
</div>
<div class="mumble-time">
<time class="time timeago" datetime="@Model.CreateTime">@Model.CreateTime</time>
</div>
</div>
</div>
<div class="mumble-content markdown-body">
@Html.Raw(await ClearHtmlAsync(Model.Markdown.MarkdownToHtml(false)))
</div>
<div class="mumble-interactive">
<div class="mumble-interactive-actions">
<div class="mumble-action-detail mumble-active">
<span>
<i class="fa fa-info-circle fa-fw"></i>详情
</span>
</div>
<div class="mumble-action-comment mumble-active">
<span>
<i class="fa fa-commenting"></i>
<span data-comment-count>@Model.CommentCount</span>
</span>
</div>
<div class="mumble-action-like">
<a href="javascript:;" data-likeid="@Model.Id">
<i class="fa fa-thumbs-up"></i>
<span data-number>@Model.Like</span>
</a>
</div>
</div>
</div>
<div class="mumble-comment" data-talk-id="@Model.Id" data-request="@Url.Action("Index", "Comment", new {node = CommentNode.Mumble, relation = Model.Id})">
<img src="@($"{Program.CdnBaseAddress}/images/loading-dark.gif")" alt="loading" class="comment-loading"/>
</div>
</div>
</div>
</div>