This task is a follow-up to T326081 (and nicely complements it). Normalize consecutive spaces, just like HTML does.
This way, the extraneous spaces wouldn't unexpectedly affect the sorting in the following cases:
Extraneous space in user input:
foo bar foo bar
Spaces around a <br> tag:
foo<br>bar foo<br> bar foo <br> bar
Note that in data-sort-value attributes, the consecutive spaces were already normalized (see my comments in T326081).