@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
|
@@ -6242,23 +6242,38 @@ var sanitizeHTML = function sanitizeHTML(html) {
|
|
|
6242
6242
|
var doc = transformers.reduce(function (value, cb) {
|
|
6243
6243
|
return cb(value);
|
|
6244
6244
|
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
6245
|
-
var
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6245
|
+
var replacers = [// remove whitespaces between some tags, as this can lead to unwanted behaviour:
|
|
6246
|
+
// - table -> empty table cells
|
|
6247
|
+
// - list -> leading whitespaces
|
|
6248
|
+
function (innerHtml) {
|
|
6249
|
+
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');
|
|
6250
|
+
}, // remove empty elements before the ending block element tag
|
|
6251
|
+
function (innerHtml) {
|
|
6252
|
+
return innerHtml.replace(/(?:<[^>^/]*>)\s*(?:<\/[^>]*>)<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1');
|
|
6253
|
+
}, // remove whitespaces before the ending block element tag
|
|
6254
|
+
function (innerHTML) {
|
|
6255
|
+
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
|
|
6252
6260
|
// capture groups explained:
|
|
6253
6261
|
// 1. and 3. every content/linebreaks before and after the div container
|
|
6254
6262
|
// 2. the table inside the container, including content and linebreaks
|
|
6255
6263
|
// The div container including attributes and possible linebreaks inside wil be removed
|
|
6256
|
-
.
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6264
|
+
replacers.unshift(function (innerHtml) {
|
|
6265
|
+
return innerHtml.replace(/(.*\s)?<div.*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>(.*\s)?/g, '$1$2$3');
|
|
6266
|
+
});
|
|
6267
|
+
}
|
|
6268
|
+
|
|
6269
|
+
var previous;
|
|
6270
|
+
|
|
6271
|
+
do {
|
|
6272
|
+
// save previous first before doing modifications
|
|
6273
|
+
previous = doc.body.innerHTML;
|
|
6274
|
+
doc.body.innerHTML = replacers.reduce(function (innerHTML, replacer) {
|
|
6275
|
+
return replacer(innerHTML);
|
|
6276
|
+
}, doc.body.innerHTML);
|
|
6262
6277
|
} while (doc.body.innerHTML !== previous);
|
|
6263
6278
|
|
|
6264
6279
|
return doc.body.innerHTML;
|