obsidian-code-block-copy icon indicating copy to clipboard operation
obsidian-code-block-copy copied to clipboard

Unintended content has 'Copy' button

Open tallguyjenks opened this issue 4 years ago • 4 comments

Love the plugin, just noticed this though:

not inside a code fence, just indented with a tab and it is being treated as code, is the intended behavior?

image image

tallguyjenks avatar Nov 09 '20 20:11 tallguyjenks

Ah yes, this is because tabbing a paragraph in markdown treats it as a code block.

But I can make the copy button NOT show for blocks without a language. Will do that soon

jdbrice avatar Nov 14 '20 00:11 jdbrice

I have some code blocks without a language (eg. AdBlock filters). Is there no other distinction between the two types of code blocks?

NomarCub avatar Nov 16 '20 13:11 NomarCub

Thats right, a tabbed code block and a fenced code block are indistinguishable in the rendered view. However, you can always add a language -> you could use adblock for those blocks. Since it is an unrecognized language it doesnt effect the highlighting anyways.

So my plan is: add a settings toggle, to optionally hide copy on blocks without a language also, I am looking into an option to put the copy button above, instead of inside the block - this way it wont overlap with text.

jdbrice avatar Nov 17 '20 15:11 jdbrice

A bit too late, but maybe this will help someone. If you just want to remove that "Copy" button, add the following to the main.js plugin file right after var pre = codeBlock.parentNode;:

// Remove "Copy" button
if (pre.children.length > 1 && pre.children[1].tagName === 'BUTTON') {
    pre.children[1].remove();
}

Also, you can add the toast notification on copy, like the original button does, just add this inside the clipboard.writeText event:

new Notice('copied to your clipboard');

Teraskull avatar Aug 17 '22 23:08 Teraskull