You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library makes it possible to compare a AngleSharp _control_`INodeList` and a _test_`INodeList` and get a list of `IDiff` differences between them.
3
5
4
6
The _control_ nodes represents the expected HTML tree, i.e. how the nodes are expected to look, and the _test_ nodes represents the nodes that should be compared to the _control_ nodes.
@@ -16,17 +18,16 @@ To find the differences between a control HTML fragment and a test HTML fragment
16
18
varcontrolHtml="<p>Hello World</p>";
17
19
vartestHtml="<p>World, I say hello</p>";
18
20
vardiffs=DiffBuilder
19
-
.Compare(controlHtml)
20
-
.WithTest(testHtml)
21
-
.WithDefaultOptions()
21
+
.Compare(control)
22
+
.WithTest(test)
22
23
.Build();
23
24
```
24
25
25
-
Read more about the available options on the [Diffing Options/Strategies](/docs/Strategies.md) page.
26
+
Read more about the available options on the [Options](/docs/Options.md) page.
Copy file name to clipboardExpand all lines: docs/Options.md
+86-62
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Diffing options/strategies:
1
+
# Diffing Options
2
2
The library comes with a bunch of options (internally referred to as strategies), for the following three main steps in the diffing process:
3
3
4
4
1. Filtering out irrelevant nodes and attributes
@@ -7,44 +7,55 @@ The library comes with a bunch of options (internally referred to as strategies)
7
7
8
8
To make it easier to configure the diffing engine, the library comes with a `DiffBuilder` class, which handles the relative complex task of setting up the `HtmlDifferenceEngine`.
9
9
10
-
Using the `UseDefaultOptions()` method is equivalent to setting the following options explicitly:
11
-
12
-
To learn how to create your own strategies, visit the [Custom Strategies](CustomStrategies.md) page.
10
+
To learn how to create your own strategies, visit the [Custom Options](CustomOptions.md) page.
13
11
14
12
The following section documents the current built-in strategies that are available.
15
13
16
14
## Default Options
17
-
In most cases, calling the `UseDefaultOptions()` method on a `DiffBuilder` instance will give you a good set of strategies for a comparison, e.g.
15
+
In most cases, calling `DiffBuilder.Compare(...).WithTest(...).Build()`will give you a good set of default options for a comparison, e.g.
18
16
19
17
```csharp
20
18
varcontrolHtml="<p>Hello World</p>";
21
19
vartestHtml="<p>World, I say hello</p>";
22
20
vardiffs=DiffBuilder
23
21
.Compare(controlHtml)
24
22
.WithTest(testHtml)
25
-
.WithDefaultOptions()
26
23
.Build();
27
24
```
28
25
29
-
Calling the `WithDefaultOptions()` method is equivalent to specifying the following options explicitly:
26
+
If you want to be more explicit, the following is equivalent to the code above:
@@ -54,28 +65,49 @@ Read more about each of the strategies below, including some that are not part o
54
65
These are the built-in filter strategies.
55
66
56
67
### Ignore comments
57
-
Enabling this strategy will ignore all comment nodes during comparison. Activate by calling the `IgnoreComments()` method on a `DiffBuilder` instance, e.g.:
68
+
Enabling this strategy will ignore all comment nodes during comparison. Activate by calling the `IgnoreComments()` method on a `IDiffingStrategyCollection` type, e.g.:
58
69
59
70
```csharp
60
71
vardiffs=DiffBuilder
61
72
.Compare(controlHtml)
62
73
.WithTest(testHtml)
63
-
.IgnoreComments()
74
+
.WithOptions(options=>options.IgnoreComments())
64
75
.Build();
65
76
```
66
77
67
78
_**NOTE**: Currently, the ignore comment strategy does NOT remove comments from CSS or JavaScript embedded in `<style>` or `<script>` tags._
68
79
80
+
### Ignore element attribute
81
+
If the `diff:ignore="true"` attribute is used on a control element (`="true"` implicit/optional), all their attributes and child nodes are skipped/ignored during comparison, including those of the test element, the control element is matched with.
82
+
83
+
In this example, the `<h1>` tag, it's attribute and children are considered the same as the element it is matched with:
84
+
85
+
```html
86
+
<header>
87
+
<h1class="heading-1"diff:ignore>Hello world</h1>
88
+
</header>
89
+
```
90
+
91
+
Activate this strategy by calling the `AddIgnoreElementSupport()` method on the `IDiffingStrategyCollection` type, e.g.:
Any attributes that starts with `diff:` are automatically filtered out before matching/comparing happens. E.g. `diff:whitespace="..."` does not show up as a missing diff when added to an control element.
71
103
72
-
To enable this option, use the `IgnoreDiffAttributes()` method on the `DiffBuilder` class, e.g.:
104
+
To enable this option, use the `IgnoreDiffAttributes()` method on the `IDiffingStrategyCollection` type, e.g.:
@@ -163,13 +195,13 @@ The following control node will be compared against the `<h1>` in the `<header>`
163
195
164
196
One use case of the CSS-selector element matcher is where you only want to test one part of a sub-tree, and ignore the rest. The example above will report the unmatched test nodes as *unexpected*, but those "diffs" can be ignored, since that is expected. This approach can save you from specifying all the needed control nodes, if only part of a sub tree needs to be compared.
165
197
166
-
To choose this matcher, use the `WithCssSelectorMatcher()` method on the `DiffBuilder` class, e.g.:
198
+
To choose this matcher, use the `AddCssSelectorMatcher()` method on the `IDiffingStrategyCollection` type, e.g.:
@@ -179,50 +211,42 @@ These are the built-in attribute matching strategies.
179
211
#### Attribute name matcher
180
212
This selector will match attributes on a control element with attributes on a test element using the attribute's name. If an *control* attribute is not matched, it is reported as *missing* and if a *test* attribute is not matched, it is reported as *unexpected*.
181
213
182
-
To choose this matcher, use the `WithAttributeNameMatcher()` method on the `DiffBuilder` class, e.g.:
214
+
To choose this matcher, use the `AddAttributeNameMatcher()` method on the `IDiffingStrategyCollection` type, e.g.:
If the `diff:ignore="true"` attribute is used on a control element (`="true"` implicit/optional), all their attributes and child nodes are skipped/ignored during comparison, including those of the test element, the control element is matched with.
210
-
211
-
In this example, the `<h1>` tag, it's attribute and children are considered the same as the element it is matched with:
212
-
213
-
```html
214
-
<header>
215
-
<h1class="heading-1"diff:ignore>Hello world</h1>
216
-
</header>
217
-
```
240
+
### Comment compare strategy
241
+
The basic comment compare strategy will simply check if the both nodes's are comments.
218
242
219
-
Activate this strategy by calling the `WithIgnoreElementSupport()` method on a `DiffBuilder` instance, e.g.:
243
+
To choose this comparer, use the `AddCommentComparer()` method on the `IDiffingStrategyCollection` type, e.g.:
@@ -267,13 +291,13 @@ To configure/override whitespace rules on a specific subtree in the comparison,
267
291
This should ensure that the meaning of the content in those tags doesn't change by default. To deal correctly with whitespace in `<style>` tags, use the [Style sheet text comparer](#style-sheet-text-comparer).
268
292
269
293
#### Perform case-_insensitve_ text comparison
270
-
To compare the text in two text nodes to each other using a case-insensitive comparison, call the `WithTextComparer(ignoreCase: true)` method on a `DiffBuilder` instance, e.g.:
294
+
To compare the text in two text nodes to each other using a case-insensitive comparison, call the `AddTextComparer(ignoreCase: true)` method on the `IDiffingStrategyCollection` type, e.g.:
@@ -301,13 +325,13 @@ The above control text would use case-insensitive regular expression to match a
301
325
#### Style sheet text comparer
302
326
Different whitespace rules apply to style sheets (style information) inside `<style>` tags, than to HTML5. This comparer will parse the style information inside `<style>` tags and compare the result of the parsing, instead doing a direct string comparison. This should remove false-positives where e.g. insignificant whitespace makes two otherwise equal set of style informations result in a diff.
303
327
304
-
To add this comparer, use the `WithStyleSheetComparer()` method on the `DiffBuilder` class, e.g.:
328
+
To add this comparer, use the `AddStyleSheetComparer()` method on the `IDiffingStrategyCollection` type, e.g.:
@@ -374,26 +398,26 @@ For example, in **strict** mode, the following are considered equal:
374
398
-`required=""` is the same as `required="required"`
375
399
-`required="required"` is the same as `required="required"`
376
400
377
-
To enable the special handling of boolean attributes, call the `WithBooleanAttributeComparer(BooleanAttributeComparision.Strict)` or `WithBooleanAttributeComparer(BooleanAttributeComparision.Loose)` on a `DiffBuilder` instance, e.g.:
401
+
To enable the special handling of boolean attributes, call the `AddBooleanAttributeComparer(BooleanAttributeComparision.Strict)` or `AddBooleanAttributeComparer(BooleanAttributeComparision.Loose)` on the `IDiffingStrategyCollection` type, e.g.:
Different whitespace rules apply to style information inside `style="..."` attributes, than to HTML5. This comparer will parse the style information inside `style="..."` attributes and compare the result of the parsing, instead doing a direct string comparison. This should remove false-positives where e.g. insignificant whitespace makes two otherwise equal set of style informations result in a diff.
389
413
390
-
To add this comparer, use the `WithStyleAttributeComparer()` method on the `DiffBuilder` class, e.g.:
414
+
To add this comparer, use the `AddStyleAttributeComparer()` method on the `IDiffingStrategyCollection` type, e.g.:
0 commit comments