Add option to ignore attributes by dchacke · Pull Request #49 · Teamwork/visual-dom-diff

I needed a way to ignore attributes because I’m diffing markdown-generated html.

Some markdown libraries assign ids to headings based on content. For example:

Will generate:

<h1 id="heading">heading</h1>

If a user changes that to # heading foo, they will only care that the content of the heading changed. They won’t care that the id changed to "heading-foo". They won’t even know that such an id even exists, so causing it to display a modification to the entire heading would only confuse the user. They would only want to see the insertion of “foo”.

I did my best to add passing tests but I was unsure about one thing: diff.ts:587, areNodesEqual(previousSibling, formattingNode) did not require the new option, for some reason. All tests already pass without changing it to areNodesEqual(previousSibling, formattingNode, false, ignoreAttributes). I don’t know why. Maybe I’m missing a test case.