Skip to content

Commit dc6b674

Browse files
committed
Updated text node comparer to use preserve whitespace by default on pre, script, and style tags.
1 parent 89fec7c commit dc6b674

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

docs/Strategies.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,14 @@ To configure/override whitespace rules on a specific subtree in the comparison,
259259
</header>
260260
```
261261

262-
**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 in-line `diff:whitespace` attribute to the `<pre>`-tag, e.g.:
262+
**Special case for `<pre>`, `<script>`, and `<style>` elements:** The content of `<pre>`, `<script>`, and `<style>` 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 in-line `diff:whitespace` attribute to the tags, e.g.:
263263

264264
```html
265265
<pre diff:whitespace="RemoveWhitespaceNodes">...</pre>
266266
```
267267

268+
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).
269+
268270
#### Perform case-_insensitve_ text comparison
269271
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.:
270272

tests/Strategies/TextNodeStrategies/TextNodeComparerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void Test005(string tag)
138138
public void Test006(string tag)
139139
{
140140
var sut = new TextNodeComparer(WhitespaceOption.Normalize);
141-
var elm = ToComparisonSource("<{tag} diff:whitespace=\"normalize\">foo bar</{tag}>");
141+
var elm = ToComparisonSource($"<{tag} diff:whitespace=\"normalize\">foo bar</{tag}>");
142142
var controlSource = new ComparisonSource(elm.Node.FirstChild, 0, elm.Path, ComparisonSourceType.Control);
143143
var testSource = ToComparisonSource("foo bar", ComparisonSourceType.Test);
144144
var comparison = new Comparison(controlSource, testSource);

0 commit comments

Comments
 (0)