Skip to content

Commit

Permalink
Update to use the bat theme for PowerShell syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw committed Jan 23, 2024
1 parent 8acc426 commit 43421b2
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion shell/Markdown.VT/ColorCode.VT/VTSyntaxHighlighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class VTSyntaxHighlighter : CodeColorizerBase
/// <param name="styles">The Custom styles to Apply to the formatted Code.</param>
/// <param name="languageParser">The language parser that the <see cref="VTSyntaxHighlighter"/> instance will use for its lifetime.</param>
public VTSyntaxHighlighter(StyleDictionary styles = null, ILanguageParser languageParser = null)
: base(styles, languageParser)
: base(styles.UseBatStyle(), languageParser)
{
_buffer = new StringBuilder(capacity: 512);

Expand Down Expand Up @@ -200,6 +200,49 @@ private void WriteCapturedStyle(Scope scope)

public static class ColorExtensionMethods
{
/// <summary>
/// Use the style from 'bat' for PowerShell syntax highlighting.
/// </summary>
internal static StyleDictionary UseBatStyle(this StyleDictionary styles)
{
if (styles is null)
{
return null;
}

styles.Remove(ScopeName.String);
styles.Remove(ScopeName.Comment);
styles.Remove(ScopeName.PowerShellOperator);
styles.Remove(ScopeName.PowerShellVariable);

styles.Add(
new Style(ScopeName.String)
{
Foreground = "\x1b[38;5;186m",
ReferenceName = "string"
});
styles.Add(
new Style(ScopeName.Comment)
{
Foreground = "\x1b[38;5;242m",
ReferenceName = "comment"
});
styles.Add(
new Style(ScopeName.PowerShellOperator)
{
Foreground = "\x1b[38;5;203m",
ReferenceName = "powershellOperator"
});
styles.Add(
new Style(ScopeName.PowerShellVariable)
{
Foreground = "\x1b[92m",
ReferenceName = "powershellVariable"
});

return styles;
}

public static string ToVTColor(this string color, bool isForeground = true)
{
if (color == null)
Expand Down

0 comments on commit 43421b2

Please sign in to comment.