@matrixreq/htmldiff 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/htmldiff.js +10 -2
- package/package.json +1 -1
- package/test/edge_cases.spec.js +10 -2
package/js/htmldiff.js
CHANGED
|
@@ -910,7 +910,15 @@
|
|
|
910
910
|
var val = tokens.map(function(token){
|
|
911
911
|
return token.string;
|
|
912
912
|
});
|
|
913
|
-
|
|
913
|
+
|
|
914
|
+
const res = wrap('ins', val, opIndex, dataPrefix, className);
|
|
915
|
+
|
|
916
|
+
// handling inserted tags, see https://matrixreq.atlassian.net/browse/MATRIX-7876
|
|
917
|
+
if (/^<[^.\/]+?>$/.exec(res)) {
|
|
918
|
+
return `${res.slice(0, res.length - 1)} data-inserted="true">`;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
return res;
|
|
914
922
|
},
|
|
915
923
|
'delete': function(op, beforeTokens, afterTokens, opIndex, dataPrefix, className){
|
|
916
924
|
var tokens = beforeTokens.slice(op.startInBefore, op.endInBefore + 1);
|
|
@@ -919,7 +927,7 @@
|
|
|
919
927
|
});
|
|
920
928
|
const res = wrap("del", val, opIndex, dataPrefix, className);
|
|
921
929
|
|
|
922
|
-
// handling cases like deleted </p><p
|
|
930
|
+
// handling cases like deleted </p><p>, see https://matrixreq.atlassian.net/browse/MATRIX-7688
|
|
923
931
|
if (/^<\/.+?><.+?>$/.exec(res) && !res.includes("del")) {
|
|
924
932
|
return `<del>${val.slice(1, val.length - 1).join("")}</del>`;
|
|
925
933
|
}
|
package/package.json
CHANGED
package/test/edge_cases.spec.js
CHANGED
|
@@ -29,5 +29,13 @@ BNXOISAN'FOSER3154
|
|
|
29
29
|
5SSDC</ins></div>`;
|
|
30
30
|
|
|
31
31
|
expect(diff(before, after)).to.eql(res);
|
|
32
|
-
})
|
|
33
|
-
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('adds data-inserted="true" to inserted tags', () => {
|
|
35
|
+
const before = `<div>some content</div>`;
|
|
36
|
+
const after = `<div><strong>some content</strong></div>`;
|
|
37
|
+
const res = `<div><strong data-inserted="true">some content</strong></div>`;
|
|
38
|
+
|
|
39
|
+
expect(diff(before, after)).to.eql(res);
|
|
40
|
+
});
|
|
41
|
+
});
|