@contentful/field-editor-rich-text 3.4.14 → 3.4.16

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,18 @@
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.16](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.15...@contentful/field-editor-rich-text@3.4.16) (2023-03-31)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **rte:** pasting tables from ms word or google docs freezes the page ([#1384](https://github.com/contentful/field-editors/issues/1384)) ([b89cd18](https://github.com/contentful/field-editors/commit/b89cd181080706a8e93992843fe937bfe63d037f))
11
+
12
+ ## [3.4.15](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.14...@contentful/field-editor-rich-text@3.4.15) (2023-03-20)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **RTE:** split up sanitize regex to prevent invalid markup ([#1377](https://github.com/contentful/field-editors/issues/1377)) ([6591252](https://github.com/contentful/field-editors/commit/659125216f52ac249b06168d4a7651a1b2dde0b7))
17
+
6
18
  ## [3.4.14](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.13...@contentful/field-editor-rich-text@3.4.14) (2023-03-16)
7
19
 
8
20
  ### Bug Fixes
@@ -6249,23 +6249,36 @@ var sanitizeHTML = function sanitizeHTML(html) {
6249
6249
  var doc = transformers.reduce(function (value, cb) {
6250
6250
  return cb(value);
6251
6251
  }, new DOMParser().parseFromString(html, 'text/html'));
6252
+ var replacers = [// remove whitespaces between some tags, as this can lead to unwanted behaviour:
6253
+ // - table -> empty table cells
6254
+ // - list -> leading whitespaces
6255
+ function (innerHtml) {
6256
+ return innerHtml.replace(/<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)(.*)>\s+<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '<$1$2$3><$4$5');
6257
+ }, // remove empty elements before the ending block element tag
6258
+ function (innerHtml) {
6259
+ return innerHtml.replace(/(?:<[^>^/]*>)\s*(?:<\/[^>]*>)<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1');
6260
+ }, // remove whitespaces before the ending block element tag
6261
+ function (innerHTML) {
6262
+ return innerHTML.replace(/\s*<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1');
6263
+ }]; // Call this replacer only if there are tables inside, as it can have a larger performance impact
6264
+
6265
+ if (doc.querySelector('table')) {
6266
+ // remove div container from tables
6267
+ // The div container including attributes and possible linebreaks inside wil be removed
6268
+ replacers.unshift(function (innerHtml) {
6269
+ var result = innerHtml.replace(/<div[^>]*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>/g, '$1');
6270
+ return result;
6271
+ });
6272
+ }
6273
+
6252
6274
  var previous;
6253
6275
 
6254
6276
  do {
6255
6277
  // save previous first before doing modifications
6256
- previous = doc.body.innerHTML; // Update the body with the cleaned up content
6257
-
6258
- doc.body.innerHTML = doc.body.innerHTML // remove div container from tables
6259
- // capture groups explained:
6260
- // 1. and 3. every content/linebreaks before and after the div container
6261
- // 2. the table inside the container, including content and linebreaks
6262
- // The div container including attributes and possible linebreaks inside wil be removed
6263
- .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:
6264
- // - table -> empty table cells
6265
- // - list -> leading whitespaces
6266
- .replace(/<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)(.*)>\s+<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '<$1$2$3><$4$5') // Removes empty elements before the closing tag of the capture group
6267
- // <p><span> </span></p> -> <p></p>
6268
- .replace(/(?:<[^>^/]*>)?\s*(?:<\/[^>]*>)?<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1');
6278
+ previous = doc.body.innerHTML;
6279
+ doc.body.innerHTML = replacers.reduce(function (innerHTML, replacer) {
6280
+ return replacer(innerHTML);
6281
+ }, doc.body.innerHTML);
6269
6282
  } while (doc.body.innerHTML !== previous);
6270
6283
 
6271
6284
  return doc.body.innerHTML;