Button Update remove Lines
This commit is contained in:
@@ -560,42 +560,50 @@
|
||||
const docRef = content.ownerDocument || document;
|
||||
const range = getSelectionRange();
|
||||
if (!range || range.collapsed) return;
|
||||
const fragment = range.extractContents();
|
||||
const unwrap = (node) => {
|
||||
const parent = node.parentNode;
|
||||
if (!parent) return;
|
||||
while (node.firstChild) parent.insertBefore(node.firstChild, node);
|
||||
parent.removeChild(node);
|
||||
};
|
||||
const strip = (node) => {
|
||||
if (!node) return;
|
||||
if (node.nodeType === 1) {
|
||||
const tag = node.tagName ? node.tagName.toUpperCase() : '';
|
||||
if (tags && tags.includes(tag)) {
|
||||
const children = Array.from(node.childNodes);
|
||||
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);
|
||||
const depth = (node) => {
|
||||
let d = 0;
|
||||
let cur = node;
|
||||
while (cur && cur !== content) {
|
||||
d += 1;
|
||||
cur = cur.parentNode;
|
||||
}
|
||||
return d;
|
||||
};
|
||||
Array.from(fragment.childNodes).forEach(strip);
|
||||
range.insertNode(fragment);
|
||||
const nodes = [];
|
||||
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();
|
||||
} catch {}
|
||||
};
|
||||
@@ -617,44 +625,52 @@
|
||||
const docRef = content.ownerDocument || document;
|
||||
const range = getSelectionRange();
|
||||
if (!range || range.collapsed) return;
|
||||
const fragment = range.extractContents();
|
||||
const unwrap = (node) => {
|
||||
const parent = node.parentNode;
|
||||
if (!parent) return;
|
||||
while (node.firstChild) parent.insertBefore(node.firstChild, node);
|
||||
parent.removeChild(node);
|
||||
};
|
||||
const strip = (node) => {
|
||||
if (!node) return;
|
||||
if (node.nodeType === 1) {
|
||||
const tag = node.tagName ? node.tagName.toUpperCase() : '';
|
||||
if (tag === 'B' || tag === 'STRONG' || tag === 'I' || tag === 'EM' || tag === 'U' || tag === 'S' || tag === 'STRIKE') {
|
||||
const children = Array.from(node.childNodes);
|
||||
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);
|
||||
const depth = (node) => {
|
||||
let d = 0;
|
||||
let cur = node;
|
||||
while (cur && cur !== content) {
|
||||
d += 1;
|
||||
cur = cur.parentNode;
|
||||
}
|
||||
return d;
|
||||
};
|
||||
Array.from(fragment.childNodes).forEach(strip);
|
||||
range.insertNode(fragment);
|
||||
const nodes = [];
|
||||
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();
|
||||
} catch {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user