Skip to content

Commit c4cdfea

Browse files
committed
Updates to readme
1 parent ee5afeb commit c4cdfea

File tree

1 file changed

+66
-16
lines changed

1 file changed

+66
-16
lines changed

README.md

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ To configure/override whitespace rules on a specific subtree in the comparison,
9494
<pre diff:whitespace="RemoveWhitespaceNodes">...</pre>
9595
```
9696

97-
**Special case for `<style>`-tags:** Even if the whitespace option is `Normalize`, whitespace inside quotes (`"` and `'` style quotes) is preserved as is. For example, the text inside the `content` style information in the following CSS will not be normalized: `p::after { content: " -.- "; }`.
98-
99-
**Special case for `<script>`-tags:** It is on the issues list to deal with whitespace properly inside `<script>`-tags.
97+
**NOTE:** It is on the issues list to deal with whitespace properly inside `<style>` and `<script>`-tags, e.g. inside strings.
10098

10199
#### Perform case-_insensitve_ text comparison
102100
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.:
@@ -159,6 +157,71 @@ var diffs = DiffBuilder
159157
.Build();
160158
```
161159

160+
### Attr Compare options
161+
The library supports various ways to perform attribute comparison.
162+
163+
#### Strict name and value comparison
164+
The *"name and value comparison"* is the base comparison option, and that will test if both the names and the values of the control and test attributes are equal. E.g.:
165+
166+
- `attr="foo"` is the same as `attr="foo"`
167+
- `attr="foo"` is the NOT same as `attr="bar"`
168+
- `foo="attr"` is the NOT same as `bar="attr"`
169+
170+
This comparison mode is on by default.
171+
172+
#### RegEx attribute value comparer
173+
It is possible to specify a regular expression in the control attributes value, and add the `:regex` postfix to the *control* attributes name, to have the comparison performed using a Regex match test. E.g.
174+
175+
- `attr:regex="foo-\d{4}"` is the same as `attr="foo-2019"`
176+
177+
#### Ignore case attribute value comparer
178+
To get the comparer to perform a case insensitive comparison of the values of the control and test attribute, add the `:ignoreCase` postfix to the *control* attributes name. E.g.
179+
180+
- `attr:ignoreCase="FOO"` is the same as `attr="foo"`
181+
182+
#### Combine ignore case and regex attribute value comparer
183+
To perform a case insenstive regular expression match, combine `:ignoreCase` and `:regex` as a postfix to the *control* attributes name. The order you combine them does not matter. E.g.
184+
185+
- `attr:ignoreCase:regex="FOO-\d{4}"` is the same as `attr="foo-2019"`
186+
- `attr:regex:ignoreCase="FOO-\d{4}"` is the same as `attr="foo-2019"`
187+
188+
#### Class attribute comparer
189+
The class attribute is special in HTML. It can contain a space separated list of CSS classes, whoes order does not matter. Therefor the library will ignore the order the CSS classes is specified in the class attribute of the control and test elements, and instead just ensure that both have the same CSS classes added to it. E.g.
190+
191+
- `class="foo bar"` is the same as `class="bar foo"`
192+
193+
To enable the special handling of the class attribute, call the `WithClassAttributeComparer()` on a `DiffBuilder` instance, e.g.:
194+
195+
```csharp
196+
var diffs = DiffBuilder
197+
.Compare(controlHtml)
198+
.WithTest(testHtml)
199+
.WithClassAttributeComparer()
200+
.Build();
201+
```
202+
203+
#### Boolean attributes comparer
204+
Another special type of attributes are the [boolean attributes](https://www.w3.org/TR/html52/infrastructure.html#sec-boolean-attributes). To make comparing these more forgiving, the boolean attribute comparer will consider two boolean attributes equal, according to these rules:
205+
206+
- In **strict** mode, a boolean attribute's value is considered truthy if the value is missing, empty, or is the name of the attribute.
207+
- In **loose** mode, a boolean attribute's value is considered truthy if the attribute is present on an element.
208+
209+
For example, in **strict** mode, the following are considered equal:
210+
211+
- `required` is the same as `required=""`
212+
- `required=""` is the same as `required="required"`
213+
- `required="required"` is the same as `required="required"`
214+
215+
To enable the special handling of boolean attributes, call the `WithBooleanAttributeComparer(BooleanAttributeComparision.Strict)` or `WithBooleanAttributeComparer(BooleanAttributeComparision.Loose)` on a `DiffBuilder` instance, e.g.:
216+
217+
```csharp
218+
var diffs = DiffBuilder
219+
.Compare(controlHtml)
220+
.WithTest(testHtml)
221+
.WithBooleanAttributeComparer(BooleanAttributeComparision.Strict)
222+
.Build();
223+
```
224+
162225
### Matching options
163226

164227
#### One-to-one matcher (node, attr)
@@ -167,19 +230,6 @@ var diffs = DiffBuilder
167230

168231
#### CSS selector-cross tree matcher (node, attr)
169232

170-
### Attr Compare options
171-
#### Name comparer (attr)
172-
#### Content comparer (attr)
173-
#### Content regex comparer (attr)
174-
#### IgnoreCase attr comparer (attr)
175-
#### Regex attr comparer (attr)
176-
#### Class attribute comparer (attr)
177-
#### Boolean-attribute comparer (attr)
178-
179-
See rules at https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
180-
https://www.w3.org/TR/html52/infrastructure.html#sec-boolean-attributes
181-
https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7
182-
183233
### Ignoring special `diff:` attributes
184234
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.
185235

0 commit comments

Comments
 (0)