Skip to content

Commit

Permalink
mark inserted tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sirenevenkii committed Sep 13, 2024
1 parent acfc5e9 commit f1793b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion js/htmldiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,15 @@
var val = tokens.map(function(token){
return token.string;
});
return wrap('ins', val, opIndex, dataPrefix, className);

const res = wrap('ins', val, opIndex, dataPrefix, className);

// handling inserted tags, see https://matrixreq.atlassian.net/browse/MATRIX-7876
if (/^<[^.\/]+?>$/.exec(res)) {
return `${res.slice(0, res.length - 1)} data-inserted="true">`;
}

return res;
},
'delete': function(op, beforeTokens, afterTokens, opIndex, dataPrefix, className){
var tokens = beforeTokens.slice(op.startInBefore, op.endInBefore + 1);
Expand Down
12 changes: 10 additions & 2 deletions test/edge_cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ BNXOISAN'FOSER3154
5SSDC</ins></div>`;

expect(diff(before, after)).to.eql(res);
})
});
});

it('adds data-inserted="true" to inserted tags', () => {
const before = `<div>some content</div>`;
const after = `<div><strong>some content</strong></div>`;
const res = `<div><strong data-inserted="true">some content</strong></div>`;

expect(diff(before, after)).to.eql(res);
});
});

0 comments on commit f1793b8

Please sign in to comment.