fixup 312424ff: process multiple top-level elements in tHTML
This commit is contained in:
parent
61971b97c8
commit
12d67fda6c
|
@ -38,11 +38,19 @@ function tHTML(html, tag) {
|
||||||
if (tag) {
|
if (tag) {
|
||||||
html = `<${tag}>${html}</${tag}>`;
|
html = `<${tag}>${html}</${tag}>`;
|
||||||
}
|
}
|
||||||
const node = (new DOMParser()).parseFromString(html, 'text/html').querySelector('body').firstElementChild;
|
const body = t.DOMParser.parseFromString(html, 'text/html').body;
|
||||||
if (html.includes('i18n-')) {
|
if (html.includes('i18n-')) {
|
||||||
tNodeList(node.getElementsByTagName('*'));
|
tNodeList(body.getElementsByTagName('*'));
|
||||||
}
|
}
|
||||||
return node;
|
// the html string may contain more than one top-level elements
|
||||||
|
if (body.childElementCount <= 1) {
|
||||||
|
return body.firstElementChild;
|
||||||
|
}
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
while (body.childElementCount) {
|
||||||
|
fragment.appendChild(body.firstElementChild);
|
||||||
|
}
|
||||||
|
return fragment;
|
||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +108,7 @@ function tNodeList(nodes) {
|
||||||
|
|
||||||
|
|
||||||
function tDocLoader() {
|
function tDocLoader() {
|
||||||
|
t.DOMParser = new DOMParser();
|
||||||
t.cache = tryJSONparse(localStorage.L10N) || {};
|
t.cache = tryJSONparse(localStorage.L10N) || {};
|
||||||
|
|
||||||
// reset L10N cache on UI language change
|
// reset L10N cache on UI language change
|
||||||
|
|
Loading…
Reference in New Issue
Block a user