I wasn't happy with how code was formatting in these posts. ChatGPT was able to help me extend Rouge highlighting built into Jekyll. I created a custom _include/after-content.html instead of modifying the default layout. The change gets applied to all {% highlight xxxx %} sections and gets implemented at build time. This likely will only work when building the site locally.
_plugins/highlight_override.rb
This puts the highlighted code block into code-block-container and adds a label for the code type and a copy code button.
This styles the block and adds functionality to the button
html
<style>.code-block-container{background-color:#1e1e1e;/* Black background */border-radius:8px;padding:10px;margin-bottom:20px;}.code-header{background-color:#333;color:#fff;padding:10px;text-align:left;display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;}.code-headerbutton{background-color:#828282;color:#fff;border:none;padding:5px;font-size:0.9rem;cursor:pointer;border-radius:5px;}.code-headerbutton:hover{background-color:#bcbabb;}.code-block::-webkit-scrollbar{height:10px;}.code-block::-webkit-scrollbar-thumb{background:#888;border-radius:5px;}.code-block::-webkit-scrollbar-thumb:hover{background:#555;}</style><script>// Adding the Copy functionality for each code blockconstcopyButtonLabel="Copy Code";// Find all code blocksletblocks=document.querySelectorAll(".code-block-container");blocks.forEach((blocks)=>{letbutton=block.querySelector(".copy-button");// Add copy button functionality if Clipboard API is supportedif (navigator.clipboard){button.addEventListener("click",async ()=>{letcode=block.querySelector("code");lettext=code.innerText;awaitnavigator.clipboard.writeText(text);// Change button text to "Code Copied" after copyingbutton.innerText="Code Copied";setTimeout(()=>{button.innerText=copyButtonLabel;},700);});}});</script>