Button Update remove Lines

This commit is contained in:
2026-01-29 01:10:56 +01:00
parent 35c7b4b85e
commit d8fcd65286
2 changed files with 75 additions and 59 deletions

View File

@@ -1 +1 @@
1.1.56 1.1.57

View File

@@ -560,42 +560,50 @@
const docRef = content.ownerDocument || document; const docRef = content.ownerDocument || document;
const range = getSelectionRange(); const range = getSelectionRange();
if (!range || range.collapsed) return; if (!range || range.collapsed) return;
const fragment = range.extractContents();
const unwrap = (node) => { const unwrap = (node) => {
const parent = node.parentNode; const parent = node.parentNode;
if (!parent) return; if (!parent) return;
while (node.firstChild) parent.insertBefore(node.firstChild, node); while (node.firstChild) parent.insertBefore(node.firstChild, node);
parent.removeChild(node); parent.removeChild(node);
}; };
const strip = (node) => { const depth = (node) => {
if (!node) return; let d = 0;
if (node.nodeType === 1) { let cur = node;
const tag = node.tagName ? node.tagName.toUpperCase() : ''; while (cur && cur !== content) {
if (tags && tags.includes(tag)) { d += 1;
const children = Array.from(node.childNodes); cur = cur.parentNode;
children.forEach(strip);
unwrap(node);
return;
}
if (styleProp && node.style) {
if (typeof clearFn === 'function') {
clearFn(node.style);
} else {
node.style[styleProp] = '';
}
const styleAttr = node.getAttribute('style');
if (!styleAttr || !String(styleAttr).trim()) {
const children = Array.from(node.childNodes);
children.forEach(strip);
unwrap(node);
return;
}
}
Array.from(node.childNodes).forEach(strip);
} }
return d;
}; };
Array.from(fragment.childNodes).forEach(strip); const nodes = [];
range.insertNode(fragment); const walker = docRef.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, null);
let node = walker.nextNode();
while (node) {
if (node !== content && range.intersectsNode(node)) {
nodes.push(node);
}
node = walker.nextNode();
}
nodes.sort((a, b) => depth(b) - depth(a));
nodes.forEach((el) => {
const tag = el.tagName ? el.tagName.toUpperCase() : '';
if (tag === 'BR') return;
if (tags && tags.includes(tag)) {
unwrap(el);
return;
}
if (styleProp && el.style) {
if (typeof clearFn === 'function') {
clearFn(el.style);
} else {
el.style[styleProp] = '';
}
const styleAttr = el.getAttribute('style');
if ((!styleAttr || !String(styleAttr).trim()) && tag === 'SPAN') {
unwrap(el);
}
}
});
saveSelection(); saveSelection();
} catch {} } catch {}
}; };
@@ -617,44 +625,52 @@
const docRef = content.ownerDocument || document; const docRef = content.ownerDocument || document;
const range = getSelectionRange(); const range = getSelectionRange();
if (!range || range.collapsed) return; if (!range || range.collapsed) return;
const fragment = range.extractContents();
const unwrap = (node) => { const unwrap = (node) => {
const parent = node.parentNode; const parent = node.parentNode;
if (!parent) return; if (!parent) return;
while (node.firstChild) parent.insertBefore(node.firstChild, node); while (node.firstChild) parent.insertBefore(node.firstChild, node);
parent.removeChild(node); parent.removeChild(node);
}; };
const strip = (node) => { const depth = (node) => {
if (!node) return; let d = 0;
if (node.nodeType === 1) { let cur = node;
const tag = node.tagName ? node.tagName.toUpperCase() : ''; while (cur && cur !== content) {
if (tag === 'B' || tag === 'STRONG' || tag === 'I' || tag === 'EM' || tag === 'U' || tag === 'S' || tag === 'STRIKE') { d += 1;
const children = Array.from(node.childNodes); cur = cur.parentNode;
children.forEach(strip);
unwrap(node);
return;
}
if (tag === 'SPAN') {
try {
node.style.fontWeight = '';
node.style.fontStyle = '';
node.style.textDecoration = '';
node.style.textDecorationLine = '';
node.style.textDecorationStyle = '';
} catch {}
const styleAttr = node.getAttribute('style');
if (!styleAttr || !String(styleAttr).trim()) {
const children = Array.from(node.childNodes);
children.forEach(strip);
unwrap(node);
return;
}
}
Array.from(node.childNodes).forEach(strip);
} }
return d;
}; };
Array.from(fragment.childNodes).forEach(strip); const nodes = [];
range.insertNode(fragment); const walker = docRef.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, null);
let node = walker.nextNode();
while (node) {
if (node !== content && range.intersectsNode(node)) {
nodes.push(node);
}
node = walker.nextNode();
}
nodes.sort((a, b) => depth(b) - depth(a));
nodes.forEach((el) => {
const tag = el.tagName ? el.tagName.toUpperCase() : '';
if (tag === 'BR') return;
if (tag === 'B' || tag === 'STRONG' || tag === 'I' || tag === 'EM' || tag === 'U' || tag === 'S' || tag === 'STRIKE') {
unwrap(el);
return;
}
if (tag === 'SPAN') {
try {
el.style.fontWeight = '';
el.style.fontStyle = '';
el.style.textDecoration = '';
el.style.textDecorationLine = '';
el.style.textDecorationStyle = '';
} catch {}
const styleAttr = el.getAttribute('style');
if (!styleAttr || !String(styleAttr).trim()) {
unwrap(el);
}
}
});
saveSelection(); saveSelection();
} catch {} } catch {}
}; };