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
Copy file name to clipboardExpand all lines: README.md
+42-7Lines changed: 42 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,14 +58,17 @@ var diffs = DiffBuilder
58
58
59
59
_**NOTE**: Currently, the ignore comment strategy does NOT remove comments from CSS or JavaScript embedded in `<style>` or `<script>` tags._
60
60
61
-
### Whitespace handling
61
+
### Text (text nodes) strategies
62
+
The built-in text strategies offer a bunch of ways to control how text (text nodes) is handled during the diffing process.
63
+
64
+
#### Whitespace handling
62
65
Whitespace can be a source of false-positives when comparing two HTML fragments. Thus, the whitespace handling strategy offer different ways to deal with it during a comparison.
63
66
64
-
-`Preserve`: Does not change or filter out any whitespace in control and test HTML. Default, same as not specifying any options.
67
+
-`Preserve` (default): Does not change or filter out any whitespace in text nodes the control and test HTML.
65
68
-`RemoveWhitespaceNodes`: Using this option filters out all text nodes that only consist of whitespace characters.
66
-
-`Normalize`: Using this option will _trim_ all text nodes and replace two or more whitespace characters with a single space character.
69
+
-`Normalize`: Using this option will _trim_ all text nodes and replace two or more whitespace characters with a single space character. This option implicitly includes the `RemoveWhitespaceNodes` option.
67
70
68
-
These options can be set either _globally_ for the entire comparison, or on a _specific subtrees in the comparison_.
71
+
These options can be set either _globally_ for the entire comparison, or inline on a _specific subtrees in the comparison_.
69
72
70
73
To set a global default, call the method `Whitespace(WhitespaceOption)` on a `DiffBuilder` instance, e.g.:
71
74
@@ -77,15 +80,15 @@ var diffs = DiffBuilder
77
80
.Build();
78
81
```
79
82
80
-
To configure/override whitespace rules on a specific subtree in the comparison, use the `diff:whitespace="WhitespaceOption"` on a control node, and it and all nodes below it will use that whitespace option, unless it is overridden on a child node. In the example below, all whitespace inside the `<h1>` element is preserved:
83
+
To configure/override whitespace rules on a specific subtree in the comparison, use the `diff:whitespace="WhitespaceOption"`inline on a control element, and it and all text nodes below it will use that whitespace option, unless it is overridden on a child element. In the example below, all whitespace inside the `<h1>` element is preserved:
**Special case for `<pre>`-tags:** The content of `<pre />`tags will always be treated as the `Preserve` option, even if whitespace strategy is globally set to `RemoveWhitespaceNodes` or `Normalize`. To override this, add a local `diff:whitespace" attribute to the tag, e.g.:
91
+
**Special case for `<pre>` elements:** The content of `<pre>`elements will always be treated as the `Preserve` option, even if whitespace option is globally set to `RemoveWhitespaceNodes` or `Normalize`. To override this, add a inline`diff:whitespace` attribute to the `<pre>`-tag, e.g.:
@@ -95,6 +98,38 @@ To configure/override whitespace rules on a specific subtree in the comparison,
95
98
96
99
**Special case for `<script>`-tags:** It is on the issues list to deal with whitespace properly inside `<script>`-tags.
97
100
101
+
#### Perform case-_insensitve_ text comparison
102
+
To compare the text in two text nodes to eachother using a case-insensitive comparison, call the `IgnoreCase()` method on a `DiffBuilder` instance, e.g.:
103
+
104
+
```csharp
105
+
vardiffs=DiffBuilder
106
+
.Compare(controlHtml)
107
+
.WithTest(testHtml)
108
+
.IgnoreCase()
109
+
.Build();
110
+
```
111
+
112
+
To configure/override ignore case rules on a specific subtree in the comparison, use the `diff:ignoreCase="true|false"` inline on a control element, and it and all text nodes below it will use that ignore case setting, unless it is overridden on a child element. In the example below, ignore case is set active for all text inside the `<h1>` element:
Note, as with all HTML5 boolean attributes, the `="true"` or `="false"` parts are optional.
121
+
122
+
#### Use regular expression when comparing text
123
+
By using the inline attribute `diff:regex` on the element containing the text node being compared, the comparer will consider the control text to be a regular expression, and will use that to test whether the test text node is as expected. This can be combined with the inline `diff:ignoreCase` attribute, to make the regular expression case-insensitive. E.g.:
124
+
125
+
```html
126
+
<header>
127
+
<h1diff:regexdiff:ignoreCase>Hello World \d{4}</h1>
128
+
</header>
129
+
```
130
+
131
+
The above control text would use case-insensitive regular expression to match against a test text string (e.g. "HELLO WORLD 2020").
132
+
98
133
### Ignore attribute
99
134
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.
0 commit comments