Copy code blocks with one click

Would be great to have the ability to copy a code block with one click. Now when you have a code block, you need to start editing a note and then precisely copy a content between backticks. It’s not very comfortable. I think, if just clicking on a code block caused copying the whole content between back ticks, it would be wonderful.

1 Like

Yep, same for me. I always have to remove the back ticks when I copy something. That’s why I often do not use the code block feature at all. But I think this should be solved when WYSIWYG is implemented.

1 Like

Update: added in the latest release! Hover for the copy button.

3 Likes

This only seems to work with three-backtick (```) code blocks, but it doesn’t seem to work with single-backtick (`) code blocks.

Personally, I use single-backtick code blocks as an alternative to block quotes and it would be very helpful to have this feature available.

Perhaps there is a very obvious reason why this is not the case, but as someone who doesn’t code, I can’t see the difference…

Steve.

Single backticks are for inline code, not multiple lines (at least not designed for), therefore copying has less utility than a full code block.

This is how inline code is typically used:

image

It’s easy to see there’s not even enough space for displaying the “Copy” button.

Is there any reason you’re not using ``` as a blockquote alternative?

If I use single backticks, the blockquote appears in red, even if it is multiple lines long.

If I use triple backticks, Dynalist tries to highlight elements of the quoted text in various colours. If I am using a code block to quote an email, for example, the highlighted elements are nonsensical.

The single backticks work fine for this, but a dedicated blockquote function (with a hovering copy button) would be even better…

Steve.

Or maybe an option in Settings to turn off code highlighting…

Steve.

I see.

Would you use multiple “>” characters for multi-line blockquotes, by the way? I feel like backtick is indeed better in this scenario, as you don’t need to prepend “>” to every paragraph like in standard Markdown.

In theory, yes. In reality, I tend to keep quotes as one block, using cmd-shift-return to leave a blank line between each paragraph.

The more I think about it, the more I think I’d prefer a simple toggle in Settings to turn off code highlighting. Even better, a per-document toggle in the “eye” menu. This way, coders could use triple-backticks as code blocks, writers could use triple-backticks as block quotes. I think it would be rare to use both styles in one document.