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

Enable `IsKeepingSourceReferences` #31

Closed SebastianStehle closed 1 year ago

SebastianStehle commented 1 year ago

New Feature Proposal

Description

I am creating a new comparer that checks how an element is closed. I got help for that from AngleSharp: https://github.com/AngleSharp/AngleSharp/issues/1107

But to implement that a flag needs to be set in the parser: IsKeepingSourceReferences

My comparer would look like this:

public static void AddElementClosingComparer(this IDiffingStrategyCollection builder)
        {
            builder.AddComparer((in Comparison source, CompareResult currentDecision) =>
            {
                if (currentDecision == CompareResult.Skip)
                {
                    return currentDecision;
                }

                if (source.Test.Node is not IElement testElement || testElement.SourceReference is not HtmlTagToken testTag)
                {
                    return currentDecision;
                }

                if (source.Control.Node is not IElement controlElement || controlElement.SourceReference is not HtmlTagToken controlTag)
                {
                    return currentDecision;
                }

                return testTag.IsSelfClosing == controlTag.IsSelfClosing ? CompareResult.Different : CompareResult.Same;
            });
        }

Can we add this flag? I could provide a PR for that. Do you think it makes sense to add this comparer as well? (Would at least be helpful to test this flag in your unit tests)

egil commented 1 year ago

Closed by 38875ff9b87412c90b7351ef5708557ba9029109