diff --git a/client/js/util/views.js b/client/js/util/views.js index c2404f63..2b39e7b1 100644 --- a/client/js/util/views.js +++ b/client/js/util/views.js @@ -246,10 +246,42 @@ function clearMessages(target) { } function htmlToDom(html) { - const parsed = domParser.parseFromString(html, 'text/html').body; - return parsed.childNodes.length > 1 ? - parsed.childNodes : - parsed.firstChild; + // code taken from jQuery + Krasimir Tsonev's blog + const wrapMap = { + _: [1, '
', '
'], + option: [1, ''], + legend: [1, '
', '
'], + area: [1, '', ''], + param: [1, '', ''], + thead: [1, '', '
'], + tr: [2, '', '
'], + td: [3, '', '
'], + col: [2, '', '
'], + }; + wrapMap.optgroup = wrapMap.option; + wrapMap.tbody = + wrapMap.tfoot = + wrapMap.colgroup = + wrapMap.caption = + wrapMap.thead; + wrapMap.th = wrapMap.td; + + let element = document.createElement('div'); + const match = /<\s*(\w+)[^>]*?>/g.exec(html); + + if (match) { + const tag = match[1]; + const [depthToChild, prefix, suffix] = wrapMap[tag] || wrapMap._; + element.innerHTML = prefix + html + suffix; + for (let i = 0; i < depthToChild; i++) { + element = element.lastChild; + } + } else { + element.innerHTML = html; + } + return element.childNodes.length > 1 ? + element.childNodes : + element.firstChild; } function getTemplate(templatePath) {