Skip to content
6 changes: 5 additions & 1 deletion ColorCode.Core/Common/ScopeName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ public class ScopeName
public const string Intrinsic = "Intrinsic";
public const string Brackets = "Brackets";
public const string Continuation = "Continuation";
public const string DiffAddition = "DiffAddition";
public const string DiffDeletion = "DiffDeletion";
public const string DiffMeta = "DiffMeta";
public const string DiffComment = "DiffComment";
}
}
}
92 changes: 92 additions & 0 deletions ColorCode.Core/Compilation/Languages/Diff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) 2015 Christopher Pardi.

// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using ColorCode.Common;

namespace ColorCode.Compilation.Languages
{
public class Diff : ILanguage
{
public string Id
{
get { return LanguageId.Diff; }
}

public string Name
{
get { return "Diff"; }
}

public string CssClassName
{
get { return "diff"; }
}

public string FirstLinePattern
{
get
{
return null;
}
}

public IList<LanguageRule> Rules
{
get
{
return new List<LanguageRule>
{
new LanguageRule(
@"^(((---)|(\*\*\*)) +\d+,\d+ +((----)|(\*\*\*\*))|@@ +\-\d+,\d+ \+\d+,\d+ +@@)(\r?\n?)",
new Dictionary<int, string>
{
{ 0, ScopeName.DiffMeta },
}),
new LanguageRule(
@"^(\*{5}).*(\*{5})(\r?\n?)",
new Dictionary<int, string>
{
{ 0, ScopeName.DiffComment },
}),
new LanguageRule(
@"^((-{3,})|(\*{3,})|(\+{3,})|(Index:)|(={3,})).*(\r?\n?)",
new Dictionary<int, string>
{
{ 0, ScopeName.DiffComment },
}),
new LanguageRule(
@"(^(\+|!).*(\r?\n?))",
new Dictionary<int, string>
{
{ 0, ScopeName.DiffAddition },
}),
new LanguageRule(
@"^\-.*(\r?\n?)",
new Dictionary<int, string>
{
{ 0, ScopeName.DiffDeletion },
}),
};
}
}

public bool HasAlias(string lang)
{
switch (lang.ToLower())
{
case "diff":
case "patch":
return true;
default:
return false;
}
}

public override string ToString()
{
return Name;
}
}
}
3 changes: 2 additions & 1 deletion ColorCode.Core/Languages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static Languages()
Load<Haskell>();
Load<Markdown>();
Load<Fortran>();
Load<Diff>();
}

/// <summary>
Expand Down Expand Up @@ -280,4 +281,4 @@ public static void Load(ILanguage language)
LanguageRepository.Load(language);
}
}
}
}
22 changes: 21 additions & 1 deletion ColorCode.Core/Styling/StyleDictionary.DefaultDark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,28 @@ public static StyleDictionary DefaultDark
{
ReferenceName = "specialChar"
},
new Style(ScopeName.DiffAddition)
{
Foreground = Green,
ReferenceName = "diffAddition"
},
new Style(ScopeName.DiffDeletion)
{
Foreground = Red,
ReferenceName = "diffDeletion"
},
new Style(ScopeName.DiffMeta)
{
Foreground = OrangeRed,
ReferenceName = "diffMeta"
},
new Style(ScopeName.DiffComment)
{
Foreground = VSDarkGray,
ReferenceName = "diffComment"
}
};
}
}
}
}
}
22 changes: 21 additions & 1 deletion ColorCode.Core/Styling/StyleDictionary.DefaultLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,28 @@ public static StyleDictionary DefaultLight
{
ReferenceName = "specialChar"
},
new Style(ScopeName.DiffAddition)
{
Foreground = Green,
ReferenceName = "diffAddition"
},
new Style(ScopeName.DiffDeletion)
{
Foreground = Red,
ReferenceName = "diffDeletion"
},
new Style(ScopeName.DiffMeta)
{
Foreground = OrangeRed,
ReferenceName = "diffMeta"
},
new Style(ScopeName.DiffComment)
{
Foreground = Gray,
ReferenceName = "diffComment"
}
};
}
}
}
}
}