diff --git a/demo.gif b/demo.gif index ad0322e..2bf9034 100644 Binary files a/demo.gif and b/demo.gif differ diff --git a/src/main.ts b/src/main.ts index 51dba26..a998fd7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -181,14 +181,24 @@ export default class CopyProtocolPlugin extends Plugin { }); 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 => { const href = link.getAttribute('href') || ''; if (href.startsWith('obsidian://copy')) { - link.classList.remove('external-link'); - link.classList.add('copy-protocol-link'); + if (link.classList.contains('external-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('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'); + } } }); }); diff --git a/styles.css b/styles.css index ad116e5..566cee9 100644 --- a/styles.css +++ b/styles.css @@ -16,34 +16,6 @@ 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 */ .markdown-rendered a[href^="obsidian://copy"] .external-link, .markdown-rendered a[href^="obsidian://copy"] + .external-link,