@contentful/field-editor-rich-text 3.4.9 → 3.4.10

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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.4.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.9...@contentful/field-editor-rich-text@3.4.10) (2023-03-09)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **RTE:** remove whitespaces only in tables and lists [TOL-104] ([#1362](https://github.com/contentful/field-editors/issues/1362)) ([8b106c8](https://github.com/contentful/field-editors/commit/8b106c8eb08d79cb6c5ae8353d5a1fcf7afab1cf))
11
+
6
12
  ## [3.4.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.8...@contentful/field-editor-rich-text@3.4.9) (2023-03-03)
7
13
 
8
14
  ### Bug Fixes
@@ -6174,15 +6174,43 @@ var stripStyleTags = function stripStyleTags(doc) {
6174
6174
  });
6175
6175
  return doc;
6176
6176
  };
6177
+ /**
6178
+ * Remove all <meta /> tags
6179
+ */
6180
+
6181
+
6182
+ var stripMetaTags = function stripMetaTags(doc) {
6183
+ doc.querySelectorAll('meta').forEach(function (el) {
6184
+ return el.remove();
6185
+ });
6186
+ return doc;
6187
+ }; // Attention: Order is important
6188
+
6177
6189
 
6178
- var transformers = [stripStyleTags, sanitizeSheets];
6190
+ var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags];
6179
6191
  var sanitizeHTML = function sanitizeHTML(html) {
6180
6192
  // Parse the HTML string and pipe it through our transformers
6181
6193
  var doc = transformers.reduce(function (value, cb) {
6182
6194
  return cb(value);
6183
6195
  }, new DOMParser().parseFromString(html, 'text/html'));
6184
- return doc.body.innerHTML.replace(/>\s+</g, '><') // Remove whitespace between tags
6185
- .replace(/(.*)<div.*>(<table.*<\/table>)<\/div>(.*)/g, '$1$2$3'); // remove div containers from tables
6196
+ var previous;
6197
+
6198
+ do {
6199
+ // save previous first before doing modifications
6200
+ previous = doc.body.innerHTML; // Update the body with the cleaned up content
6201
+
6202
+ doc.body.innerHTML = doc.body.innerHTML // remove div container from tables
6203
+ // capture groups explained:
6204
+ // 1. and 3. every content/linebreaks before and after the div container
6205
+ // 2. the table inside the container, including content and linebreaks
6206
+ // The div container including attributes and possible linebreaks inside wil be removed
6207
+ .replace(/(.*\s)?<div.*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>(.*\s)?/g, '$1$2$3') // remove whitespaces between some tags, as this can lead to unwanted behaviour:
6208
+ // - table -> empty table cells
6209
+ // - list -> leading whitespaces
6210
+ .replace(/<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)(.*)>\s+</g, '<$1$2$3><');
6211
+ } while (doc.body.innerHTML !== previous);
6212
+
6213
+ return doc.body.innerHTML;
6186
6214
  };
6187
6215
 
6188
6216
  /**