M3X-720: Enhance ins/del wrapping on atomic tags while diffing#5
Open
ragoolkr wants to merge 3 commits into
Open
M3X-720: Enhance ins/del wrapping on atomic tags while diffing#5ragoolkr wants to merge 3 commits into
ragoolkr wants to merge 3 commits into
Conversation
…age nested tags and improve test coverage for edge cases
…ic tokens close correctly when depth returns to zero.
sirenevenkii
reviewed
Jul 3, 2026
…cy; improve test coverage for self-closing tags in html_to_tokens.spec.js.
sirenevenkii
approved these changes
Jul 3, 2026
sirenevenkii
left a comment
Collaborator
There was a problem hiding this comment.
looks good. great improvement.
please, clean up the comments and styling before merging.
| */ | ||
| function isOpeningTagOf(word, tag){ | ||
| var tagText = word.substring(word.lastIndexOf('<')); | ||
| if (tagText.indexOf('>') !== tagText.length - 1) return false; |
Collaborator
There was a problem hiding this comment.
do not use inline conditions. same for closing tag
| * @return {boolean} True if the word is now a complete token (including the end tag), | ||
| * false otherwise. | ||
| * @return {boolean} True if word ends with an opening (non-self-closing) tag for the given | ||
| * atomic tag name. |
Collaborator
There was a problem hiding this comment.
it's not about specifically atomic tags, isn't? same for isClosingTagOf comment
Comment on lines
+91
to
+92
| // inspect the last tag in word (from its opening '<'); to an earlier '>' in that | ||
| // slice means loose text e.g. "a > b" in a <script>, not a tag, so they bail out. |
Collaborator
There was a problem hiding this comment.
why those comment are inline?
Collaborator
There was a problem hiding this comment.
paraphrase it, I'm struggling to understand what you mean here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
This pull request introduces significant improvements to the HTML diffing logic, focusing on more robust handling of atomic tags.
ISSUE
In html-diff when we have the tag with data-html-diff-id we consider them atomic and wrap them with ins/del. we decide opening and close of the atomic tag based on the tag name.
Sometimes we might have a structure where
then diffing algorithm finds the
data-htmldiff-idstarts the wrapping process it looks for the atomic tag which is<span>then it starts looking for the closing tag</span>but in our structure since it also has a child<span>the algorithm considers child's closing</span>as the parent one and produces something like thisFIX
So now we track how many tags with same name currently open inside the atomic token old code closed atomic tag at first nested spans cut early broken markup.we count open/close depth, closes only when depth at 0 → whole nested block stays one balanced token.
Core logic improvements:
<iframe>,<script>, and custom tags withdata-htmldiff-id), ensuring each atomic tag is wrapped independently in diffs, and supporting nested and adjacent atomic tags.Fix counts open/close depth, closes only at depth 0 → whole nested block stays one balanced token.
Testing and CI:
Package metadata:
package.jsonto reflect new ownership (@matrixreq/htmldiff), version bump to 1.4.0, and repository links.These changes collectively make the diffing library more reliable for complex HTML structures and easier to maintain and test.