Last active
September 10, 2025 06:15
-
-
Save technoscavenger/5bc4690da8fcb945d94b9eb742f5ddef to your computer and use it in GitHub Desktop.
Highlight.js Blogger modification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <link href='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css' rel='stylesheet'/> | |
| <script src='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js'/> | |
| <script type='text/javascript'> | |
| hljs.configure({cssSelector: "code"}); | |
| hljs.highlightAll(); | |
| </script> | |
| <script type='text/javascript'> | |
| //<![CDATA[ | |
| hljs.addPlugin({ | |
| "after:highlightElement": ({ el, text }) => { | |
| const wrapper = el.parentElement; | |
| if (wrapper == null) { | |
| return; | |
| } | |
| wrapper.style.position = 'relative'; | |
| const copyButton = document.createElement("button"); | |
| copyButton.style.position = 'absolute'; | |
| copyButton.style.top = '8px'; | |
| copyButton.style.right = '8px'; | |
| copyButton.style.padding = '3px 6px'; // Slightly reduced padding | |
| copyButton.style.border = '1px solid #ccc'; | |
| copyButton.style.borderRadius = '3px'; // Slightly reduced border radius | |
| copyButton.style.backgroundColor = '#f0f0f0'; | |
| copyButton.style.color = '#333'; | |
| copyButton.style.cursor = 'pointer'; | |
| // Lucide copy icon with reduced size (75% of original) | |
| copyButton.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`; | |
| copyButton.onclick = () => { | |
| navigator.clipboard.writeText(text); | |
| // Notify user that the content has been copied | |
| // (Assuming 'toast' library is available) | |
| if (typeof toast !== 'undefined' && toast.success) { | |
| toast.success("Copied to clipboard", { | |
| description: "The code block content has been copied to the clipboard.", | |
| }); | |
| } | |
| }; | |
| wrapper.appendChild(copyButton); | |
| }, | |
| }); | |
| //]]> | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment