AngleSharp / AngleSharp.Diffing

A library that makes it possible to compare two AngleSharp node lists and get a list of differences between them.
MIT License
37 stars 6 forks source link

OrderedStyleAttributeComparer.cs #26

Closed SebastianStehle closed 2 years ago

SebastianStehle commented 2 years ago

Types of Changes

Prerequisites

Please make sure you can check the following two boxes:

Contribution Type

What types of changes does your code introduce? Put an x in all the boxes that apply:

Description

Closes #17

I am not happy with the implementation. It sucks that I have to make the Split, but it should not matter, because the library is usually not used in performance critical scenarios I guess.

Because the csstext seems to be normalized it should work fine.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

egil commented 2 years ago

Also, please add a new section to the changelog.md at the top that looks a bit like this:

# 0.18.0

Released on ??, ??, 2022.

- Added <WRITE DESCRIPTION OF ADDITION HERE>. By [@SebastianStehle](https://github.com/SebastianStehle).
egil commented 2 years ago

To round things off, it would be fantastic if you could write a small section for the wiki on this new feature that goes below this one: https://github.com/AngleSharp/AngleSharp.Diffing/wiki/Diffing-Options#style-attribute-comparer

Just add it here as a comment and I will move it to the WIKI when this is merged.

SebastianStehle commented 2 years ago

I have implemented your change requests.

Here is what I would add to the wiki:


When styles are parsed they are also normalized. This means that the following styles would be identical:

But if you have multiple styles the order matters and is therefore not changed. The following styles are different:

To add a style comparer where the order does not matter you can register the style comparer with the optional parameter ignoreOrder=true:

var diffs = DiffBuilder
    .Compare(controlHtml)
    .WithTest(testHtml)
    .WithOptions(options => options.AddStyleAttributeComparer(ignoreOrder: true))
    .Build();
egil commented 2 years ago

@FlorianRappl does the version scheme for AngleSharp projects allow us to make breaking changes while only going from 0.17.0 to 0.18.0?

Technically, adding the extra parameter ignoreOrder to AddStyleAttributeComparer(ignoreOrder: true) is consider a breaking change by Microsoft.

FlorianRappl commented 2 years ago

Does the version scheme for AngleSharp projects allow us to make breaking changes while only going from 0.17.0 to 0.18.0?

Well, in general we advise to keep everything at the same base level to indicate compatibility with AngleSharp.Core, however, here it seems we are anyway not aligned. Maybe let's re-align with AngleSharp v1.0?

In any case yes, adding an additional parameter (or modifying a signature) is unfortunately breaking in C#. If that is not desired my advise would be to add a new method instead of making the overload - thus introducing no breaking change. (However, as stated I personally have no objection against breaking changes / going to 0.18 or whatever right now).

egil commented 2 years ago

Maybe let's re-align with AngleSharp v1.0?

Yes. Lets do that. I will keep the overload in this case as it makes more sense to me. After AngleSharp reaches v1 we can switch a more proper use of semantic versioning and align all projects on that.