fix: replace css-masks with native setIcon to bypass browser feature warnings; update demo.gif

This commit is contained in:
JLDiaz (m) 2026-05-21 21:01:50 +02:00
parent 724e45534b
commit d74842f728
3 changed files with 13 additions and 31 deletions

BIN
demo.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View file

@ -181,14 +181,24 @@ export default class CopyProtocolPlugin extends Plugin {
}); });
this.registerMarkdownPostProcessor((element, context) => { this.registerMarkdownPostProcessor((element, context) => {
const links = element.querySelectorAll('a.external-link'); const links = element.querySelectorAll('a.external-link, a.copy-protocol-link');
links.forEach(link => { links.forEach(link => {
const href = link.getAttribute('href') || ''; const href = link.getAttribute('href') || '';
if (href.startsWith('obsidian://copy')) { if (href.startsWith('obsidian://copy')) {
link.classList.remove('external-link'); if (link.classList.contains('external-link')) {
link.classList.add('copy-protocol-link'); link.classList.remove('external-link');
}
if (!link.classList.contains('copy-protocol-link')) {
link.classList.add('copy-protocol-link');
}
link.removeAttribute('aria-label'); link.removeAttribute('aria-label');
link.removeAttribute('data-tooltip-position'); link.removeAttribute('data-tooltip-position');
// Add an inline icon span if it doesn't already have one
if (!link.querySelector('.copy-protocol-icon')) {
const span = link.createSpan({ cls: 'copy-protocol-icon' });
setIcon(span, 'copy');
}
} }
}); });
}); });

View file

@ -16,34 +16,6 @@
padding-inline-end: 0; padding-inline-end: 0;
} }
.markdown-rendered a.copy-protocol-link::after,
.markdown-preview-view a.copy-protocol-link::after,
.markdown-rendered a.external-link[href^="obsidian://copy"]::after,
.markdown-preview-view a.external-link[href^="obsidian://copy"]::after {
content: "";
display: inline-block;
width: 0.85em;
height: 0.85em;
margin-left: 5px;
vertical-align: middle;
background-color: currentColor;
background-image: none; /* Clears Obsidian's default icon if set via background-image */
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='14' height='14' x='8' y='8' rx='2' ry='2'/%3E%3Cpath d='M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'/%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='14' height='14' x='8' y='8' rx='2' ry='2'/%3E%3Cpath d='M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'/%3E%3C/svg%3E");
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
opacity: 0.8;
}
.markdown-rendered a.copy-protocol-link:hover::after,
.markdown-preview-view a.copy-protocol-link:hover::after,
.markdown-rendered a.external-link[href^="obsidian://copy"]:hover::after,
.markdown-preview-view a.external-link[href^="obsidian://copy"]:hover::after {
opacity: 1;
}
/* Hide Obsidian's default external link icon elements in Reading Mode */ /* Hide Obsidian's default external link icon elements in Reading Mode */
.markdown-rendered a[href^="obsidian://copy"] .external-link, .markdown-rendered a[href^="obsidian://copy"] .external-link,
.markdown-rendered a[href^="obsidian://copy"] + .external-link, .markdown-rendered a[href^="obsidian://copy"] + .external-link,