Add language and clipboard buttons to code blocks
This commit is contained in:
parent
da89510eee
commit
f3b603a82a
5 changed files with 50 additions and 6 deletions
|
@ -59,6 +59,24 @@ window.addEventListener("load", () => {
|
||||||
endAudio: elevatorButton.dataset.endAudio,
|
endAudio: elevatorButton.dataset.endAudio,
|
||||||
preloadAudio: false,
|
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", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
|
@ -54,11 +54,31 @@ div.block-mermaid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div.block-code .highlight {
|
div.block-code {
|
||||||
pre,
|
.filename {
|
||||||
span,
|
font-family: $family-code;
|
||||||
& {
|
background-color: $grey-lighter;
|
||||||
@include dark-mode;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,4 @@ $code-background: none;
|
||||||
$pre-background: none;
|
$pre-background: none;
|
||||||
$code-padding: 0;
|
$code-padding: 0;
|
||||||
$code: inherit;
|
$code: inherit;
|
||||||
|
$content-pre-padding: 2.75rem 1.25rem 1.25rem 1.25rem;
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
// Ensure animations aren't for the initial transition
|
// Ensure animations aren't for the initial transition
|
||||||
html.dark-mode-animate & {
|
html.dark-mode-animate & {
|
||||||
transition-duration: 0.5s;
|
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 & {
|
html.dark-mode & {
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
|
<span class="filename">
|
||||||
|
{{ value.language }}
|
||||||
|
<i class="fa-regular fa-clipboard is-clickable code-copy" title="Copy to clipboard"></i>
|
||||||
|
</span>
|
||||||
{{ value.code }}
|
{{ value.code }}
|
||||||
|
|
Loading…
Reference in a new issue