@contentful/field-editor-rich-text 3.4.13 → 3.4.15

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.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)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **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))
11
+
12
+ ## [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)
13
+
14
+ ### Bug Fixes
15
+
16
+ - not removing whitespaces around inline elements [TOL-1041] ([#1374](https://github.com/contentful/field-editors/issues/1374)) ([2ebfb43](https://github.com/contentful/field-editors/commit/2ebfb432e9fcb841298b72401089b5248bd84c93))
17
+
6
18
  ## [3.4.13](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.12...@contentful/field-editor-rich-text@3.4.13) (2023-03-14)
7
19
 
8
20
  **Note:** Version bump only for package @contentful/field-editor-rich-text
@@ -6249,21 +6249,38 @@ 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 previous;
6253
-
6254
- do {
6255
- // 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
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
6259
6267
  // capture groups explained:
6260
6268
  // 1. and 3. every content/linebreaks before and after the div container
6261
6269
  // 2. the table inside the container, including content and linebreaks
6262
6270
  // 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+</g, '<$1$2$3><');
6271
+ replacers.unshift(function (innerHtml) {
6272
+ return innerHtml.replace(/(.*\s)?<div.*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>(.*\s)?/g, '$1$2$3');
6273
+ });
6274
+ }
6275
+
6276
+ var previous;
6277
+
6278
+ do {
6279
+ // save previous first before doing modifications
6280
+ previous = doc.body.innerHTML;
6281
+ doc.body.innerHTML = replacers.reduce(function (innerHTML, replacer) {
6282
+ return replacer(innerHTML);
6283
+ }, doc.body.innerHTML);
6267
6284
  } while (doc.body.innerHTML !== previous);
6268
6285
 
6269
6286
  return doc.body.innerHTML;