Skip to content

Commit d48e449

Browse files
authored
docs: improve examples of semantic comparison modifiers
1 parent 1704137 commit d48e449

1 file changed

Lines changed: 35 additions & 15 deletions

File tree

docs/site/docs/verification/semantic-html-comparison.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ The [AngleSharp Diffing](https://github.com/AngleSharp/AngleSharp.Diffing/) libr
2626

2727
The [AngleSharp Diffing](https://github.com/AngleSharp/AngleSharp.Diffing/) library also allows us to customize the comparison process by adding special attributes to the _"control" markup_, i.e. the expected markup we want to use in verification.
2828

29+
All the customization options below will match with the following markup:
30+
31+
```html
32+
<header>
33+
<h1 id="head-1">
34+
Hello <em>world</em>
35+
</h1>
36+
</header>
37+
```
38+
2939
Here are the customization options you have available to you:
3040

3141
- **Ignore comments (enabled by default):** Comments in markup and inside `<style>` tags are automatically ignored and not part of the comparison process.
@@ -34,39 +44,39 @@ Here are the customization options you have available to you:
3444

3545
```html
3646
<header>
37-
<h1 class="heading-1" diff:ignore>Hello world</h1>
47+
<h1 diff:ignore></h1>
3848
</header>
3949
```
4050

41-
- **Ignore attribute:** To ignore an attribute during comparison, add the `:ignore` modifier to the attribute (no value is needed). For example, to ignore the `class` attribute:
51+
- **Ignore attribute:** To ignore an attribute during comparison, add the `:ignore` modifier to the attribute (no value is needed). For example, to ignore the `id` attribute:
4252

4353
```html
4454
<header>
45-
<h1 class:ignore>Hello world</h1>
55+
<h1 id:ignore>Hello <em>world</em></h1>
4656
</header>
4757
```
4858

4959
- **Ignore children:** Use the `diff:ignoreChildren` attribute (no value is needed) to ignore all child nodes/elements of an element. This does not include attributes. For example, to ignore all child nodes of the `h1` element, do the following:
5060

5161
```html
5262
<header>
53-
<h1 diff:ignoreChildren>Hello <span>world</span></h1>
63+
<h1 id="head-1" diff:ignoreChildren></h1>
5464
</header>
5565
```
5666

5767
- **Ignore all attributes:** Use the `diff:ignoreAttributes` attribute (no value is needed) to ignore all attributes of an element. For example:
5868

5969
```html
6070
<header>
61-
<h1 diff:ignoreAttributes>Hello world</h1>
71+
<h1 diff:ignoreAttributes>Hello <em>world</em></h1>
6272
</header>
6373
```
6474

6575
> [!NOTE]
6676
> The `diff:ignoreChildren` and `diff:ignoreAttributes` attributes can be combined to ignore all child nodes/element *and* attributes of an element, but still verify that the element itself exists. For example:
6777
```html
6878
<header>
69-
<h1 diff:ignoreChildren diff:ignoreAttributes>Hello world</h1>
79+
<h1 diff:ignoreChildren diff:ignoreAttributes></h1>
7080
</header>
7181

7282
- **Configure whitespace handling:** By default, all nodes and elements are compared using the `Normalize` whitespace handling option. The `Normalize` option will trim all text nodes and replace two or more whitespace characters with a single space character. The other options are `Preserve`, which will leave all whitespace unchanged, and `RemoveWhitespaceNodes`, which will only remove empty text nodes.
@@ -75,41 +85,51 @@ Here are the customization options you have available to you:
7585

7686
```html
7787
<header>
78-
<h1 diff:whitespace="preserve">Hello <em> woooorld</em></h1>
88+
<h1 id="head-1" diff:whitespace="preserve">
89+
Hello <em>world</em>
90+
</h1>
7991
</header>
8092
```
8193

8294
> [!NOTE]
8395
> The default for `<pre>` and `<script>` elements is the `Preserve` option. To change that, use the `diff:whitespace` attribute. For example:
8496
8597
```html
86-
<pre diff:whitespace="RemoveWhitespaceNodes">...</pre>
98+
<header>
99+
<h1 id="head-1" diff:whitespace="RemoveWhitespaceNodes">Hello<em>world</em></pre>
100+
</header>
87101
```
88102

89103
- **Perform case-insensitive comparison:** By default, all text comparison is case sensitive, but if you want to perform a case-insensitive comparison of text inside elements or attributes, use the `diff:ignoreCase` attribute on elements and `:ignoreCase` modifier on attributes. For example, to perform a case insensitive comparison of the text in the following `h1` element , do the following:
90104

91105
```html
92-
<h1 diff:ignoreCase>HellO WoRlD</h1>
106+
<header>
107+
<h1 id="head-1" diff:ignoreCase>HeLLo <em>world</em></h1>
108+
</header
93109
```
94110

95-
To perform case insensitive comparison of the text inside the `title` attribute, do the following:
111+
To perform case insensitive comparison of the text inside the `id` attribute, do the following:
96112

97113
```html
98-
<h1 title:ignoreCase="HeaDinG">...</h1>
114+
<header>
115+
<h1 id:ignoreCase="HeAD-1">Hello <em>world</em></h1>
116+
</header>
99117
```
100118

101119
- **Use RegEx during comparison:** To use a regular expression when comparing the text inside an element or inside an attribute, use the `diff:regex` attribute on elements and the `:regex` modifier on attributes.
102120

103-
For example, to use a regular expression during comparison of the text in the `h1` element, add the `diff:regex` attribute to the element and place the regular expression in the body of the element:
121+
For example, to use a regular expression during comparison of the text in the `em` element, add the `diff:regex` attribute to the element and place the regular expression in the body of the element:
104122

105123
```html
106-
<h1 diff:regex diff:ignoreCase>Hello World \d{4}</h1>
124+
<header>
125+
<h1 id="head-1">Hello <em diff:regex>\w</em></h1>
126+
</header>
107127
```
108128

109-
To use a regular expression during comparison of the text inside the `title` attribute, add the `:regex` modifier to the attribute and add the regular expression in the attribute's value:
129+
To use a regular expression during comparison of the text inside the `id` attribute, add the `:regex` modifier to the attribute and add the regular expression in the attribute's value:
110130

111131
```html
112-
<h1 title:regex="Heading-\d{4}">...</h1>
132+
<h1 id:regex="head-\d{1}">...</h1>
113133
```
114134

115135
> [!NOTE]

0 commit comments

Comments
 (0)