@contentful/field-editor-rich-text 3.4.14 → 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 +6 -0
- package/dist/field-editor-rich-text.cjs.development.js +28 -13
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +28 -13
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/package.json +2 -2
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.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
|
+
|
|
6
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)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
|
@@ -6249,23 +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
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
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
|
-
.
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
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);
|
|
6269
6284
|
} while (doc.body.innerHTML !== previous);
|
|
6270
6285
|
|
|
6271
6286
|
return doc.body.innerHTML;
|