From 4774286edacb65fb4de09998d70b09be31d8c237 Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Thu, 21 Mar 2024 12:17:29 +0100 Subject: [PATCH] Added syntax highlighting for the yaml language --- Wave/Utilities/MarkdownUtilities.cs | 3 +- .../SyntaxHighlighting/YamlLanguage.cs | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Wave/Utilities/SyntaxHighlighting/YamlLanguage.cs diff --git a/Wave/Utilities/MarkdownUtilities.cs b/Wave/Utilities/MarkdownUtilities.cs index 751343f..c8d9506 100644 --- a/Wave/Utilities/MarkdownUtilities.cs +++ b/Wave/Utilities/MarkdownUtilities.cs @@ -21,7 +21,8 @@ public static class MarkdownUtilities { Class = "max-w-full" }) .UseColorCode(HtmlFormatterType.Style, StyleDictionary.DefaultDark, [ - new ShellLanguage() + new ShellLanguage(), + new YamlLanguage() ]) .DisableHtml() .Build(); diff --git a/Wave/Utilities/SyntaxHighlighting/YamlLanguage.cs b/Wave/Utilities/SyntaxHighlighting/YamlLanguage.cs new file mode 100644 index 0000000..129aab1 --- /dev/null +++ b/Wave/Utilities/SyntaxHighlighting/YamlLanguage.cs @@ -0,0 +1,33 @@ +using ColorCode; + +namespace Wave.Utilities.SyntaxHighlighting; + +#nullable disable + +public class YamlLanguage : ILanguage { + public string Id => "yml"; + public string FirstLinePattern => null; + public string Name => "Yaml"; + public string CssClassName => "yml"; + + public IList Rules { get; } = [ + new LanguageRule(@"(?:\w+):", new Dictionary { + {0, ColorCode.Common.ScopeName.XmlAttribute} + }), + new LanguageRule(@"#(?:.*)\b", new Dictionary { + {0, ColorCode.Common.ScopeName.Comment} + }), + new LanguageRule("[^\\\\]\"(?:.*?)[^\\\\]\"", new Dictionary { + {0, ColorCode.Common.ScopeName.String} + }), + new LanguageRule(@"\-(?:\s\w.+)\b", new Dictionary { + {0, ColorCode.Common.ScopeName.XmlAttributeValue} + }) + ]; + + public bool HasAlias(string lang) { + return string.Equals(lang, "yml", StringComparison.CurrentCultureIgnoreCase) || + string.Equals(lang, "yaml", StringComparison.CurrentCultureIgnoreCase); + } + +} \ No newline at end of file