Skip to content

Enable IsKeepingSourceReferences #31

@SebastianStehle

Description

@SebastianStehle

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions