fix: Use DOMParser in is_html + Handle unparsable html string with jquery
This commit is contained in:
parent
2b9aa25520
commit
bec966ab7d
2 changed files with 9 additions and 12 deletions
|
|
@ -116,8 +116,9 @@ frappe.ui.form.Layout = class Layout {
|
|||
// wrap in a block if `html` does not contain html tags
|
||||
$html = $("<div class='form-message border-bottom'></div>").text(html);
|
||||
} else {
|
||||
$html = $(html);
|
||||
$html.addClass("form-message border-bottom");
|
||||
// Wrap in a block just in case the string does not begin with a tag
|
||||
// as Jquery assumes it to be a CSS selector and breaks.
|
||||
$html = $("<div class='form-message border-bottom'>").html(html);
|
||||
}
|
||||
|
||||
// Add close button to block if not permanent
|
||||
|
|
|
|||
|
|
@ -157,16 +157,12 @@ Object.assign(frappe.utils, {
|
|||
is_html: function (txt) {
|
||||
if (!txt) return false;
|
||||
|
||||
if (
|
||||
txt.indexOf("<br>") == -1 &&
|
||||
txt.indexOf("<p") == -1 &&
|
||||
txt.indexOf("<img") == -1 &&
|
||||
txt.indexOf("<div") == -1 &&
|
||||
!txt.includes("<span")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
const doc = new DOMParser().parseFromString(txt, "text/html");
|
||||
const nodes = doc.body.childNodes || [];
|
||||
|
||||
// check if any of the nodes are element nodes
|
||||
// Ref: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
|
||||
return [...nodes].some((node) => node.nodeType === 1);
|
||||
},
|
||||
is_mac: function () {
|
||||
return window.navigator.platform === "MacIntel";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue