tHTML uses parseFromString instead of innerHTML. showHelp now uses tHTML
This commit is contained in:
parent
5d46dcc33e
commit
61971b97c8
11
edit/edit.js
11
edit/edit.js
|
@ -1936,17 +1936,10 @@ function showRegExpTester(event, section = getSectionForChild(this)) {
|
|||
});
|
||||
}
|
||||
|
||||
function showHelp(title, text) {
|
||||
function showHelp(title, body) {
|
||||
const div = $('#help-popup');
|
||||
div.classList.remove('big');
|
||||
|
||||
const contents = $('.contents', div);
|
||||
if (text instanceof HTMLElement) {
|
||||
contents.textContent = '';
|
||||
contents.appendChild(text);
|
||||
} else {
|
||||
contents.innerHTML = text;
|
||||
}
|
||||
$('.contents', div).appendChild(tHTML(body));
|
||||
$('.title', div).textContent = title;
|
||||
|
||||
if (getComputedStyle(div).display === 'none') {
|
||||
|
|
|
@ -28,13 +28,23 @@ function tE(id, key, attr, esc) {
|
|||
}
|
||||
|
||||
|
||||
function tHTML(html) {
|
||||
const node = document.createElement('div');
|
||||
node.innerHTML = html.replace(/>\s+</g, '><'); // spaces are removed; use for an explicit space
|
||||
if (html.includes('i18n-')) {
|
||||
tNodeList(node.getElementsByTagName('*'));
|
||||
function tHTML(html, tag) {
|
||||
// body is a text node without HTML tags
|
||||
if (typeof html === 'string' && /<\w+/.test(html) === false) {
|
||||
return document.createTextNode(html);
|
||||
}
|
||||
return node.firstElementChild;
|
||||
if (typeof html === 'string') {
|
||||
html = html.replace(/>\s+</g, '><'); // spaces are removed; use for an explicit space
|
||||
if (tag) {
|
||||
html = `<${tag}>${html}</${tag}>`;
|
||||
}
|
||||
const node = (new DOMParser()).parseFromString(html, 'text/html').querySelector('body').firstElementChild;
|
||||
if (html.includes('i18n-')) {
|
||||
tNodeList(node.getElementsByTagName('*'));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user