summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/backend.js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2016-11-07 12:02:13 +0100
committerChristophe Matthieu <chm@odoo.com>2016-11-07 12:02:13 +0100
commitaf865c2e9ea1dc1890ef33add9a6e4bc657068e0 (patch)
tree125bdc3bfa3b826202a616ec155b9bfc66485aa5 /addons/web_editor/static/src/js/backend.js
parent62b3de52dccc1c6b9e16e5a86320524efb474ad4 (diff)
[FIX] web_editor: widget html preview doesn't match wysiwig editor (widget html iframe)
The widget html is used for plain text and html content. Need to check if the content is a valid html code, if is not wrap with p tag every lines. opw-692158
Diffstat (limited to 'addons/web_editor/static/src/js/backend.js')
-rw-r--r--addons/web_editor/static/src/js/backend.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js
index 671e89a2b7f..0cd9abb5596 100644
--- a/addons/web_editor/static/src/js/backend.js
+++ b/addons/web_editor/static/src/js/backend.js
@@ -113,11 +113,16 @@ var FieldTextHtmlSimple = widget.extend({
},
text_to_html: function (text) {
var value = text || "";
- if (value.match(/^\s*$/)) {
- value = '<p><br/></p>';
- } else {
- value = "<p>"+value.split(/<br\/?>/).join("<br/></p><p>")+"</p>";
- value = value.replace(/<p><\/p>/g, '').replace('<p><p>', '<p>').replace('<p><p ', '<p ').replace('</p></p>', '</p>');
+ try {
+ $(text)[0].innerHTML;
+ return text;
+ } catch (e) {
+ if (value.match(/^\s*$/)) {
+ value = '<p><br/></p>';
+ } else {
+ value = "<p>"+value.split(/<br\/?>/).join("<br/></p><p>")+"</p>";
+ value = value.replace(/<p><\/p>/g, '').replace('<p><p>', '<p>').replace('<p><p ', '<p ').replace('</p></p>', '</p>');
+ }
}
return value;
},