jackfiled
a483ddc671
All checks were successful
Build blog docker image / Build-Blog-Image (push) Successful in 3m57s
Reviewed-on: #3
30 lines
862 B
C#
30 lines
862 B
C#
using AngleSharp;
|
|
using AngleSharp.Dom;
|
|
using YaeBlog.Core.Abstractions;
|
|
using YaeBlog.Core.Models;
|
|
|
|
namespace YaeBlog.Core.Processors;
|
|
|
|
public class CodeBlockPostRenderProcessor : IPostRenderProcessor
|
|
{
|
|
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
|
{
|
|
BrowsingContext context = new(Configuration.Default);
|
|
IDocument document = await context.OpenAsync(
|
|
req => req.Content(essay.HtmlContent));
|
|
|
|
IEnumerable<IElement> preElements = from e in document.All
|
|
where e.LocalName == "pre"
|
|
select e;
|
|
|
|
foreach (IElement element in preElements)
|
|
{
|
|
element.ClassList.Add("p-3 text-bg-secondary rounded-1");
|
|
}
|
|
|
|
return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml);
|
|
}
|
|
|
|
public string Name => nameof(CodeBlockPostRenderProcessor);
|
|
}
|