Hi,
This is not really an Obsidian question but there are a lot of knowleadgeable and helpful people in this community that perhaps can help. I’m using one of the community plugins (the Pandoc plugin) to export markdown as HTML. One nice feature of the plugin is that it injects the following piece of code to create buttons that allow one to copy the contents of code blocks to the clipboard:
<button class="copy-code-button">Copy</button>
I have figured out how to make this work with the following JavaScript block:
<script>
window.onload = function() {
const preElements = document.querySelectorAll('pre');
preElements.forEach((pre, index) => {
const button = pre.querySelector('button');
const code = pre.querySelector('code');
button.addEventListener('click', () => {
navigator.clipboard.writeText(code.innerHTML);
});
});
}
</script>
I guess I can have this as a snippet and add it manually to every HTML document that I generate but I’m sure there must be some more efficient and elegant way to do this. I figure it must involve adding this somewhere in the template that the plugin uses to generate the HTML. I don’t know how to do this, though.
Can anybody suggest a good way to achieve this goal?