This commit is contained in:
2026-01-30 23:32:07 +01:00
parent 3d5dfe1cca
commit 721ca7282a
2 changed files with 23 additions and 20 deletions

View File

@@ -114,10 +114,15 @@
Array.from(wrapper.querySelectorAll('*')).forEach((el) => {
const tag = el.tagName;
const tagLower = tag.toLowerCase();
if (inlineTags.has(tag)) {
if (tagLower === 'a' && !el.getAttribute('href')) {
unwrap(el, false);
return;
}
Array.from(el.attributes).forEach((attr) => {
const name = attr.name.toLowerCase();
if (tag === 'a') {
if (tagLower === 'a') {
if (!['href', 'target', 'rel', 'style', 'class'].includes(name)) {
el.removeAttribute(attr.name);
}
@@ -945,11 +950,6 @@
return;
}
restoreSelection();
const range = savedRange ? savedRange.cloneRange() : getSelectionRange();
if (!range || range.collapsed) {
hideLinkPanel();
return;
}
try {
const linkEl = findLinkAtSelection();
if (linkEl && linkEl.setAttribute) {
@@ -958,19 +958,22 @@
return;
}
} catch {}
exec('createLink', url);
const linkAfter = findLinkAtSelection();
if (!linkAfter) {
try {
const docRef = content.ownerDocument || document;
const anchor = docRef.createElement('a');
anchor.setAttribute('href', url);
anchor.setAttribute('target', '_blank');
anchor.setAttribute('rel', 'noopener');
const fragment = range.extractContents();
anchor.appendChild(fragment);
range.insertNode(anchor);
} catch {}
const range = savedRange ? savedRange.cloneRange() : getSelectionRange();
if (!range || range.collapsed) {
hideLinkPanel();
return;
}
try {
const docRef = content.ownerDocument || document;
const anchor = docRef.createElement('a');
anchor.setAttribute('href', url);
anchor.setAttribute('target', '_blank');
anchor.setAttribute('rel', 'noopener');
const fragment = range.extractContents();
anchor.appendChild(fragment);
range.insertNode(anchor);
} catch {
exec('createLink', url);
}
hideLinkPanel();
});