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

Self closing comparer. #32

Closed SebastianStehle closed 1 year ago

SebastianStehle commented 1 year 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 #30,#31

SebastianStehle commented 1 year ago

Thanks, I have fixed the XML comments.

egil commented 1 year ago

Two more things:

  1. Please add an "Unreleased" section at the top of the changelog.md file, and write a line about your change in a similar fashion used previously.
  2. Create an update for the docs page (https://github.com/AngleSharp/AngleSharp.Diffing/wiki/Diffing-Options), just a small section that covers your new compare in the appropriate section, such that other users can discover your contribution in the future.

Feel free to write the markdown here in the PR as a comment and I will move it over to the wiki page. My plan is to drop using the wiki and move the content into a docs folder so that the docs can be in sync with the code.

SebastianStehle commented 1 year ago

Added the changelog.

Here is my stuff for the wiki

--

Element compare strategy

The element closing compare strategy will simply check if both nodes are elements and if the elements are closed the same way. If you add this comparer, <br /> and <br> are marked as different.

This comparer is not part of the default options. To choose this comparer, use the AddElementClosingComparer() method on the IDiffingStrategyCollection type, e.g.:

var diffs = DiffBuilder
    .Compare(controlHtml)
    .WithTest(testHtml)
    .WithOptions(options => options.AddElementClosingComparer())
    .Build();

Btw: It is not optimal that I cannot add metadata to the diff. In this case, I think you don't know why there is a diff. Btw: Can you push it to nuget today?

egil commented 1 year ago

Btw: It is not optimal that I cannot add metadata to the diff. In this case, I think you don't know why there is a diff. Btw: Can you push it to nuget today?

Yeah, we could consider adding a way to report more back than just a CompareResult. A workaround you can employ is to cast IDiff to NodeDiff, which has a reference to the Control and Test nodes, and that will allow you to inspect the nodes themselves and that way determine if it is a closing tag difference, the same way that the new comparer you have created does it.

egil commented 1 year ago

Just waiting for @FlorianRappl's take on setting IsKeepingSourceReferences = true to true before merging.

If you are in a hurry @SebastianStehle, just create a local version of HtmlDiffer in your own project.