diff --git a/static/src/js/base.js b/static/src/js/base.js index b5ecde0..988f363 100644 --- a/static/src/js/base.js +++ b/static/src/js/base.js @@ -59,6 +59,24 @@ window.addEventListener("load", () => { endAudio: elevatorButton.dataset.endAudio, preloadAudio: false, }); + + document.querySelectorAll(".block-code").forEach((codeBlock) => { + const clipboardIcon = codeBlock.querySelector(".code-copy"); + clipboardIcon.addEventListener("click", (event) => { + event.preventDefault(); + navigator.clipboard + .writeText(codeBlock.querySelector("pre").textContent) + .then(() => { + clipboardIcon.classList.remove("fa-regular", "fa-clipboard"); + clipboardIcon.classList.add("fa-solid", "fa-check"); + + setTimeout(() => { + clipboardIcon.classList.add("fa-regular", "fa-clipboard"); + clipboardIcon.classList.remove("fa-solid", "fa-check"); + }, 3000); + }); + }); + }); }); window.addEventListener("DOMContentLoaded", () => { diff --git a/static/src/scss/_blocks.scss b/static/src/scss/_blocks.scss index a5168a3..aa57236 100644 --- a/static/src/scss/_blocks.scss +++ b/static/src/scss/_blocks.scss @@ -54,11 +54,31 @@ div.block-mermaid { } } -div.block-code .highlight { - pre, - span, - & { - @include dark-mode; +div.block-code { + .filename { + font-family: $family-code; + background-color: $grey-lighter; + font-size: 1rem; + position: relative; + text-align: right; + transform: translateY(100%) translateX(-100%); + display: inline-block; + left: 100%; + padding: 0.25rem 1rem; + border-radius: 0 0 0 $radius-large; + box-shadow: $shadow; + + @include dark-mode { + background-color: $grey-darker; + } + } + + .highlight { + pre, + span, + & { + @include dark-mode; + } } } diff --git a/static/src/scss/_bulma_overrides.scss b/static/src/scss/_bulma_overrides.scss index 009530c..d2cc2c1 100644 --- a/static/src/scss/_bulma_overrides.scss +++ b/static/src/scss/_bulma_overrides.scss @@ -20,3 +20,4 @@ $code-background: none; $pre-background: none; $code-padding: 0; $code: inherit; +$content-pre-padding: 2.75rem 1.25rem 1.25rem 1.25rem; diff --git a/static/src/scss/_mixins.scss b/static/src/scss/_mixins.scss index c4ae385..948bd49 100644 --- a/static/src/scss/_mixins.scss +++ b/static/src/scss/_mixins.scss @@ -2,7 +2,8 @@ // Ensure animations aren't for the initial transition html.dark-mode-animate & { transition-duration: 0.5s; - transition-property: color, background-color, border-color, filter; + transition-property: color, background-color, border-color, filter, + box-shadow; } html.dark-mode & { diff --git a/website/contrib/code_block/templates/contrib/blocks/code.html b/website/contrib/code_block/templates/contrib/blocks/code.html index 97af219..ddb1a9c 100644 --- a/website/contrib/code_block/templates/contrib/blocks/code.html +++ b/website/contrib/code_block/templates/contrib/blocks/code.html @@ -1 +1,5 @@ + + {{ value.language }} + + {{ value.code }}