mirror of
https://github.com/jldiaz/copy-protocol-plugin.git
synced 2026-07-22 06:56:55 +00:00
fix: replace css-masks with native setIcon to bypass browser feature warnings; update demo.gif
This commit is contained in:
parent
724e45534b
commit
d74842f728
3 changed files with 13 additions and 31 deletions
BIN
demo.gif
BIN
demo.gif
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.7 MiB |
16
src/main.ts
16
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');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
28
styles.css
28
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue