diff --git a/Wave/Utilities/MarkdownUtilities.cs b/Wave/Utilities/MarkdownUtilities.cs index 030cf19..751343f 100644 --- a/Wave/Utilities/MarkdownUtilities.cs +++ b/Wave/Utilities/MarkdownUtilities.cs @@ -1,7 +1,9 @@ -using Markdig; +using ColorCode.Styling; +using Markdig; using Markdig.Extensions.MediaLinks; using Microsoft.AspNetCore.Components; using Markdown.ColorCode; +using Wave.Utilities.SyntaxHighlighting; namespace Wave.Utilities; @@ -18,7 +20,9 @@ public static class MarkdownUtilities { AddControlsProperty = true, Class = "max-w-full" }) - .UseColorCode() + .UseColorCode(HtmlFormatterType.Style, StyleDictionary.DefaultDark, [ + new ShellLanguage() + ]) .DisableHtml() .Build(); return Markdig.Markdown.ToHtml(markdown, pipeline); diff --git a/Wave/Utilities/SyntaxHighlighting/ShellLanguage.cs b/Wave/Utilities/SyntaxHighlighting/ShellLanguage.cs new file mode 100644 index 0000000..cf4ba37 --- /dev/null +++ b/Wave/Utilities/SyntaxHighlighting/ShellLanguage.cs @@ -0,0 +1,27 @@ +using ColorCode; + +namespace Wave.Utilities.SyntaxHighlighting; + +public class ShellLanguage : ILanguage { + public string Id => "shell"; + public string FirstLinePattern => @"^\s*\$.*"; + public string Name => "Shell"; + public string CssClassName => "shell"; + + public IList Rules { get; } = [ + new LanguageRule(@"\$\s*\w[\w\d]+\b", new Dictionary { + {0, ColorCode.Common.ScopeName.PowerShellCommand} + }), + new LanguageRule(@"(?:\s(\-\w|\-\-\w\w+)\b)", new Dictionary { + {0, ColorCode.Common.ScopeName.PowerShellParameter} + }), + new LanguageRule("[^\\\\]\"(?:.*?)[^\\\\]\"", new Dictionary { + {0, ColorCode.Common.ScopeName.String} + }) + ]; + + public bool HasAlias(string lang) { + return false; + } + +} \ No newline at end of file