Added syntax highlighting for the shell language

This commit is contained in:
Mia Rose Winter 2024-03-21 11:42:32 +01:00
parent afe9627438
commit 85e654f231
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
2 changed files with 33 additions and 2 deletions

View file

@ -1,7 +1,9 @@
using Markdig; using ColorCode.Styling;
using Markdig;
using Markdig.Extensions.MediaLinks; using Markdig.Extensions.MediaLinks;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Markdown.ColorCode; using Markdown.ColorCode;
using Wave.Utilities.SyntaxHighlighting;
namespace Wave.Utilities; namespace Wave.Utilities;
@ -18,7 +20,9 @@ public static class MarkdownUtilities {
AddControlsProperty = true, AddControlsProperty = true,
Class = "max-w-full" Class = "max-w-full"
}) })
.UseColorCode() .UseColorCode(HtmlFormatterType.Style, StyleDictionary.DefaultDark, [
new ShellLanguage()
])
.DisableHtml() .DisableHtml()
.Build(); .Build();
return Markdig.Markdown.ToHtml(markdown, pipeline); return Markdig.Markdown.ToHtml(markdown, pipeline);

View file

@ -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<LanguageRule> Rules { get; } = [
new LanguageRule(@"\$\s*\w[\w\d]+\b", new Dictionary<int, string> {
{0, ColorCode.Common.ScopeName.PowerShellCommand}
}),
new LanguageRule(@"(?:\s(\-\w|\-\-\w\w+)\b)", new Dictionary<int, string> {
{0, ColorCode.Common.ScopeName.PowerShellParameter}
}),
new LanguageRule("[^\\\\]\"(?:.*?)[^\\\\]\"", new Dictionary<int, string> {
{0, ColorCode.Common.ScopeName.String}
})
];
public bool HasAlias(string lang) {
return false;
}
}