[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
This commit is contained in:
Christophe Matthieu
2016-11-07 12:02:13 +01:00
parent 62b3de52dc
commit af865c2e9e
+10 -5
View File
@@ -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;
},