This plugin is designed to add a copy code button to code blocks in TiddlyWiki, making it easier to copy code snippets with their formatting and indentation intact. In TiddlyWiki, code blocks are typically wrapped in the <pre> tag to preserve their formatting and indentation. However, copying the code manually can be inconvenient.
This plugin solves this problem by adding a “Copy Code” button next to the code block. Clicking the button copies the code to the clipboard, and the copied code is also displayed in a popup using the SweetAlert2 plugin, making it easy to verify that the code was copied successfully.
This plugin can greatly improve the efficiency and convenience of displaying and sharing code in TiddlyWiki, especially when you need to copy code frequently.
The only downside at the moment is that the copy button needs to be manually triggered for display.
I’m trying to rework it so that it doesn’t have any dependencies. @oeyoews do you by any chance still have the non-uglified version of the JS in the rewritten $:/core/modules/widgets/codeblock.js?
This would make things much easier.
Anyway, I have achieved a reasonable result already:
The copy button is highlighted when hovered and a hover text is displayed:
I don’t know much about JS, so I have made only minimal changes. I have commented out the unnecessary parts of JS instead of removing them, for testing.
JS of codeblock widget introduces no button content, it is introduced through CSS pseudoelements, for easier editing without touching the widget definition.
I ended up using emoji as the button icon, it was easier to handle than SVG icons, and is less intrusive than a button with “Copy” text.
I think it looks and works reasonably now, but there is surely a lot of room for improvement. I’ll report here with any updates.
I tried it, and it seems to be more convenient, except that the language type icon of the code block cannot be configured, but in addition, the copy-to-clipboard text seems to be unhideable. Is there any way to hide it? Consider that not all situations require text, an icon is enough.
This is a quick implementation of tailwindcss, everything works perfectly except the code type language highlighting is not working properly yet @saqimtiaz