diff --git a/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs b/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs index 217aa38..2325c07 100644 --- a/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs +++ b/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs @@ -1,11 +1,12 @@ using AngleSharp; using AngleSharp.Dom; +using Microsoft.Extensions.Logging; using YaeBlog.Core.Abstractions; using YaeBlog.Core.Models; namespace YaeBlog.Core.Processors; -public class CodeBlockPostRenderProcessor : IPostRenderProcessor +public class CodeBlockPostRenderProcessor(ILogger logger) : IPostRenderProcessor { public async Task ProcessAsync(BlogEssay essay) { @@ -20,10 +21,34 @@ public class CodeBlockPostRenderProcessor : IPostRenderProcessor foreach (IElement element in preElements) { element.ClassList.Add("p-3 text-bg-secondary rounded-1"); + + IEnumerable codeElements = from e in element.Children + where e.LocalName == "code" + select e; + + foreach (IElement code in codeElements) + { + string? language = (from c in code.ClassList + where c.StartsWith("language-") + select c[9..].ToLower()).FirstOrDefault(); + + if (language is null) + { + continue; + } + + logger.LogDebug("Detect code block of language {}.", language); + code.InnerHtml = HighLightCode(code.InnerHtml, language); + } } return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml); } public string Name => nameof(CodeBlockPostRenderProcessor); + + private static string HighLightCode(string code, string language) + { + return code; + } } diff --git a/YaeBlog.Core/Processors/Scanners/CSharpScanner.cs b/YaeBlog.Core/Processors/Scanners/CSharpScanner.cs new file mode 100644 index 0000000..c5923ef --- /dev/null +++ b/YaeBlog.Core/Processors/Scanners/CSharpScanner.cs @@ -0,0 +1,9 @@ +using static LanguageExt.Prelude; + + +namespace YaeBlog.Core.Processors.Scanners; + +public class CSharpScanner +{ + +} diff --git a/YaeBlog.Core/YaeBlog.Core.csproj b/YaeBlog.Core/YaeBlog.Core.csproj index ef44f03..00cb827 100644 --- a/YaeBlog.Core/YaeBlog.Core.csproj +++ b/YaeBlog.Core/YaeBlog.Core.csproj @@ -12,6 +12,8 @@ + +