Closed robertoostenveld closed 1 year ago
Getting the button to appear on the top-right of the code block turned out to be difficult, as it is positioned relative to the page, not relative to the highlighted code snippet. Replacing append()
in the javascript code by prepend()
resulted in the button being the first element, after which it can be moved to the right of the page.
Relevant to getting it to work was that the javascript should only run after all page content is loaded, otherwise it would not find the code snippets. I implemented that using defer
, in an example somewhere else I noticed https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event being used.
This is inspired by github and many other websites that show a lot of code.
It can follow the implementation on https://remarkablemark.org/blog/2021/06/01/add-copy-code-to-clipboard-button-to-jeyll-site/