@contentful/field-editor-rich-text 3.4.17 → 3.4.18

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.
@@ -6237,6 +6237,16 @@ var stripMetaTags = function stripMetaTags(doc) {
6237
6237
 
6238
6238
 
6239
6239
  var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags, sanitizeAnchors];
6240
+
6241
+ function removeTableWrappers(table) {
6242
+ var parent = table.parentElement;
6243
+
6244
+ if (parent && parent.tagName === 'DIV' && parent.children.length === 1) {
6245
+ parent.replaceWith(table);
6246
+ removeTableWrappers(table);
6247
+ }
6248
+ }
6249
+
6240
6250
  var sanitizeHTML = function sanitizeHTML(html) {
6241
6251
  // Parse the HTML string and pipe it through our transformers
6242
6252
  var doc = transformers.reduce(function (value, cb) {
@@ -6253,17 +6263,7 @@ var sanitizeHTML = function sanitizeHTML(html) {
6253
6263
  }, // remove whitespaces before the ending block element tag
6254
6264
  function (innerHTML) {
6255
6265
  return innerHTML.replace(/\s*<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1');
6256
- }]; // Call this replacer only if there are tables inside, as it can have a larger performance impact
6257
-
6258
- if (doc.querySelector('table')) {
6259
- // remove div container from tables
6260
- // The div container including attributes and possible linebreaks inside wil be removed
6261
- replacers.unshift(function (innerHtml) {
6262
- var result = innerHtml.replace(/<div[^>]*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>/g, '$1');
6263
- return result;
6264
- });
6265
- }
6266
-
6266
+ }];
6267
6267
  var previous;
6268
6268
 
6269
6269
  do {
@@ -6272,8 +6272,12 @@ var sanitizeHTML = function sanitizeHTML(html) {
6272
6272
  doc.body.innerHTML = replacers.reduce(function (innerHTML, replacer) {
6273
6273
  return replacer(innerHTML);
6274
6274
  }, doc.body.innerHTML);
6275
- } while (doc.body.innerHTML !== previous);
6275
+ } while (doc.body.innerHTML !== previous); // Removing the div container wrappers from tables
6276
+ // The div container including attributes and possible linebreaks inside wil be removed
6277
+ // TODO: can be removed with plate >= 20
6278
+
6276
6279
 
6280
+ doc.querySelectorAll('table').forEach(removeTableWrappers);
6277
6281
  return doc.body.innerHTML;
6278
6282
  };
6279
6283