Rohland / htmldiff.net

Html Diff algorithm for .NET
MIT License
288 stars 83 forks source link

Failed to detect inline style changed #21

Open vle-dev opened 8 years ago

vle-dev commented 8 years ago

Hi @Rohland At first, thank you so much for this great tool. My question is: is there any workaround to detect the inline changed as below? I've looked in the discussion on http://www.rohland.co.za/index.php/2009/10/31/csharp-html-diff-algorithm/ and it seems the case very similar to user 'tats' during June 7, 2010. `[Test] public void Execute_DetectInlineStyleChanged_Test() { // Arrange var oldText = @"

SECOND

"; var newText = @"

SECOND

"; // Act var diff = new global::HtmlDiff.HtmlDiff(oldText, newText).Build();

        // Assert
        Assert.IsFalse(diff.Contains("color:#00FFFF"));
        Assert.IsTrue(diff.Contains("em"));
    }`
santokh3386 commented 7 years ago

Hi @Rohland , This has been a wonderful effort and i appreciate it. It is working perfectly except in the condition mentioned in the above condition. Can you please put light on that how can we solve this issue..

I tried making two document using CKEditor and that always contains inline tags and style which is ignored by the tool.

Expecting response AS Soon as you can..

Thanks a lot in advance..

Santokh.. :)

GBriotti commented 5 years ago

Hi all. I've found a problem (and probably a solution) related to this issue.

The Diff class use a Stack _specialTagDiffStack to keep track of special inline style tag. Unfortunately this works only if the inline tags are only on "one side" (i.e. deleted or inserted) but it doesn't work if there is a replace (say, changing from bold to italic).

This is probably due to the fact that if tags are on the same side, for well formed html the closures are encountered in reversal order respect to the opening tags, Thus LIFO works fine.

But when there is a replace, the closures are parsed in the same order of the openings.

I solved this using two stacks: _specialTagDiffStackIns and _specialTagDiffStackDel. It seems to work, but tests are in progress.