EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
email body html to plain fix
Yuri Kuznetsovd8249c449ba4
diff --git a/client/src/views/email/fields/body.js b/client/src/views/email/fields/body.jsindex 4411d9b9a5..702db34bb8 100644--- a/client/src/views/email/fields/body.js+++ b/client/src/views/email/fields/body.js@@ -271,6 +271,10 @@ class EmailBodyFieldView extends WysiwygFieldView {data[this.name] += this.replyPart;}+ if (this.model.attributes.isHtml) {+ data[this.name + 'Plain'] = this.htmlToPlain(data[this.name]);+ }+return data;}}diff --git a/client/src/views/fields/wysiwyg.js b/client/src/views/fields/wysiwyg.jsindex de5b6128a4..91d46bd319 100644--- a/client/src/views/fields/wysiwyg.js+++ b/client/src/views/fields/wysiwyg.js@@ -767,7 +767,50 @@ class WysiwygFieldView extends TextFieldView {return html.replace(/\n/g, '<br>');}- htmlToPlain(text) {+ /**+ * @protected+ * @param {string} html+ * @return {string}+ */+ htmlToPlain(html) {+ const div = document.createElement('div');+ div.innerHTML = html;++ /**+ * @param {Node|HTMLElement} node+ * @return {string}+ */+ function processNode(node) {+ if (node.nodeType === Node.TEXT_NODE) {+ return node.nodeValue;+ }++ if (node.nodeType === Node.ELEMENT_NODE) {+ if (node instanceof HTMLAnchorElement) {+ return `${node.textContent} (${node.href})`;+ }++ if (node instanceof HTMLQuoteElement) {+ return `> ${node.textContent.trim()}`;+ }++ switch (node.tagName.toLowerCase()) {+ case 'br':+ case 'p':+ case 'div':+ return `\n${Array.from(node.childNodes).map(processNode).join('')}\n`;+ }++ return Array.from(node.childNodes).map(processNode).join('');+ }++ return '';+ }++ return processNode(div).replace(/\n{2,}/g, '\n\n').trim();+ }++ /*htmlToPlain(text) {text = text || '';let value = text@@ -782,7 +825,7 @@ class WysiwygFieldView extends TextFieldView {value = $div.text();return value;- }+ }*/disableWysiwygMode() {this.destroySummernote();