AngleSharp / AngleSharp.Diffing

A library that makes it possible to compare two AngleSharp node lists and get a list of differences between them.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable `IsKeepingSourceReferences`

SebastianStehle opened this issue · comments

New Feature Proposal

Description

I am creating a new comparer that checks how an element is closed. I got help for that from AngleSharp: AngleSharp/AngleSharp#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)

Closed by 38875ff