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

@@ -1 +1 @@
1.1.63 1.1.64

View File

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