You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ok, I wonder which of the strategies being added are causing this. Is it only this exact configuration that causes this? If not, do you mind reducing the example down as much as possible.
The first, "<!--comment-->", is from the test of ForwardSearchingNodeMatcher, which is the matcher used when calling AddSearchingNodeMatcher, so I would think it would work.
@SebastianStehle, sorry for the very long response time on this. Here is what happens:
When you use the WithOptions call, you are responsible for adding in all the compares, matches, filters, etc., since the defaults options are not used.
The default options/configuration is, by the way, this:
So to make your code work, you just have to call .AddCommentComparer() in the builder options, otherwise the differ does not know how to compare comments. By default, comments are ignored if you do use WithOptions.
using AngleSharp.Diffing;
using AngleSharp.Diffing.Strategies.AttributeStrategies;
using AngleSharp.Diffing.Strategies.TextNodeStrategies;
var comment = "<!-- [endif] -->";
var diffs =
DiffBuilder
.Compare(comment)
.WithTest(comment)
.WithOptions(options => options
.AddAttributeComparer()
.AddAttributeNameMatcher()
.AddBooleanAttributeComparer(BooleanAttributeComparision.Strict)
.AddClassAttributeComparer()
.AddCssSelectorMatcher()
.AddElementComparer()
.AddIgnoreElementSupport()
.AddSearchingNodeMatcher()
.AddStyleAttributeComparer()
.AddStyleSheetComparer()
.AddTextComparer(WhitespaceOption.Normalize, ignoreCase: false)
+ .AddCommentComparer()
.IgnoreDiffAttributes()
)
.Build();
Console.WriteLine(diffs.Count());
Activity
egil commentedon Mar 15, 2022
Does this still break if you just do?
Does this happy to other types of comments? E.g.:
<!-- comment --><!-- -->SebastianStehle commentedon Mar 15, 2022
No, this works. It also happens with other comments. Both empty and with a text.
egil commentedon Mar 15, 2022
Sorry, which of my questions are you referring to?
SebastianStehle commentedon Mar 15, 2022
Your code works,
With my code both comments do not work.
egil commentedon Mar 15, 2022
Ok, I wonder which of the strategies being added are causing this. Is it only this exact configuration that causes this? If not, do you mind reducing the example down as much as possible.
SebastianStehle commentedon Mar 15, 2022
This is the smallest config I could come up with:
egil commentedon Mar 15, 2022
OK, interesting, thanks.
Does all these cases fail?
The first,
"<!--comment-->", is from the test ofForwardSearchingNodeMatcher, which is the matcher used when callingAddSearchingNodeMatcher, so I would think it would work.SebastianStehle commentedon Mar 15, 2022
Yes, all these fail in my case. I also added the test to my fork and it fails there as well.
egil commentedon Mar 15, 2022
Ok, thanks. That will take some additional investigation.
egil commentedon Feb 3, 2023
@SebastianStehle, sorry for the very long response time on this. Here is what happens:
When you use the
WithOptionscall, you are responsible for adding in all the compares, matches, filters, etc., since the defaults options are not used.The default options/configuration is, by the way, this:
So to make your code work, you just have to call
.AddCommentComparer()in the builder options, otherwise the differ does not know how to compare comments. By default, comments are ignored if you do useWithOptions.using AngleSharp.Diffing; using AngleSharp.Diffing.Strategies.AttributeStrategies; using AngleSharp.Diffing.Strategies.TextNodeStrategies; var comment = "<!-- [endif] -->"; var diffs = DiffBuilder .Compare(comment) .WithTest(comment) .WithOptions(options => options .AddAttributeComparer() .AddAttributeNameMatcher() .AddBooleanAttributeComparer(BooleanAttributeComparision.Strict) .AddClassAttributeComparer() .AddCssSelectorMatcher() .AddElementComparer() .AddIgnoreElementSupport() .AddSearchingNodeMatcher() .AddStyleAttributeComparer() .AddStyleSheetComparer() .AddTextComparer(WhitespaceOption.Normalize, ignoreCase: false) + .AddCommentComparer() .IgnoreDiffAttributes() ) .Build(); Console.WriteLine(diffs.Count());