@matrixreq/htmldiff 1.5.0 → 1.6.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 CHANGED
@@ -74,7 +74,15 @@
74
74
  // incomplete name, e.g. detecting '<abbr>' as the atomic tag 'a' while reading '<a'.
75
75
  var defaultAtomicTagsRegExp = new RegExp('^<(iframe|object|math|svg|script|video|head|style|a)[\\s/>]');
76
76
  var atomicTagsRegExp = defaultAtomicTagsRegExp;
77
- const dataHtmlDiffIdRegExp = /^<([a-z\-]+).+data-htmldiff-id=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))*.)["']?/;
77
+
78
+ /**
79
+ * Matches an element whose own opening tag carries data-htmldiff-id; captures tag name and
80
+ * attribute value. The skip before the attribute is quote aware, so it cannot run past '>'
81
+ * into a nested child. The leading \s prevents matching 'x-data-htmldiff-id'.
82
+ * @see isStartOfAtomicTag and createToken.
83
+ */
84
+ const dataHtmlDiffIdRegExp =
85
+ /^<([a-z\-]+)(?:[^>"']|"[^"]*"|'[^']*')*\sdata-htmldiff-id=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))*.)["']?/;
78
86
 
79
87
  /**
80
88
  * Opt-in marker for the recursive inner diff. When two matched atomic tokens (typically
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@matrixreq/htmldiff",
3
3
  "description": "Diff and markup HTML with <ins> and <del> tags",
4
4
  "companyname": "Matrix Requirements",
5
- "version": "1.5.0",
5
+ "version": "1.6.0",
6
6
  "keywords": [
7
7
  "diff",
8
8
  "html",
@@ -155,6 +155,17 @@ describe('htmlToTokens', function(){
155
155
  expect(cut(atomic)).eql(tokenize([atomic]));
156
156
  });
157
157
 
158
+ it('should key a wrapper by its own data-htmldiff-id, not a nested child one', function(){
159
+ var atomic = '<strong data-htmldiff-id="s1">' +
160
+ '<em data-htmldiff-id="e1">C</em></strong>';
161
+ expect(cut(atomic)[0].key).eql('s1');
162
+ });
163
+
164
+ it('should not key an unkeyed atomic tag by a nested child data-htmldiff-id', function(){
165
+ var atomic = '<a><em data-htmldiff-id="e1">C</em></a>';
166
+ expect(cut(atomic)[0].key).eql('<a>');
167
+ });
168
+
158
169
  it('should not bump depth on differently-named tags that share a prefix', function(){
159
170
  // a tag must not be matched by an atomic tag named "a" appearing as <article>.
160
171
  var atomic = '<a href="x"><article>hi</article></a>';