-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathIgnoreElementComparer.cs
More file actions
29 lines (25 loc) · 931 Bytes
/
IgnoreElementComparer.cs
File metadata and controls
29 lines (25 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
namespace AngleSharp.Diffing.Strategies.ElementStrategies;
/// <summary>
/// Represents the ignore element comparer.
/// </summary>
public static class IgnoreElementComparer
{
private const string DIFF_IGNORE_ATTRIBUTE = "diff:ignore";
/// <summary>
/// The ignore element comparer.
/// </summary>
public static CompareResult Compare(in Comparison comparison, CompareResult currentDecision)
{
if (currentDecision.Decision.HasFlag(CompareDecision.Skip))
return currentDecision;
return ControlHasTruthyIgnoreAttribute(comparison)
? CompareResult.Skip
: currentDecision;
}
private static bool ControlHasTruthyIgnoreAttribute(in Comparison comparison)
{
return comparison.Control.Node is IElement element &&
element.TryGetAttrValue(DIFF_IGNORE_ATTRIBUTE, out bool shouldIgnore) &&
shouldIgnore;
}
}