Add code copy button
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
90d78f9abb
commit
7f6548e805
2 changed files with 13 additions and 17 deletions
|
@ -1,7 +1,4 @@
|
||||||
.content pre button {
|
.content code .a {
|
||||||
position: absolute;
|
|
||||||
top: 5px;
|
|
||||||
right: 5px;}.content code .a {
|
|
||||||
color: #483D8B;
|
color: #483D8B;
|
||||||
}
|
}
|
||||||
.content code .b {
|
.content code .b {
|
||||||
|
@ -155,7 +152,6 @@
|
||||||
color: #483D8B;
|
color: #483D8B;
|
||||||
}
|
}
|
||||||
.content pre {
|
.content pre {
|
||||||
position: relative;
|
|
||||||
border: 1px solid #999;
|
border: 1px solid #999;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
const copyButtonLabel = "Copy Code";
|
const copyButtonLabel = "Copy Code";
|
||||||
|
|
||||||
// use a class selector if available
|
// use a class selector if available
|
||||||
|
if (navigator.clipboard) {
|
||||||
let blocks = document.querySelectorAll("pre");
|
let blocks = document.querySelectorAll("pre");
|
||||||
|
|
||||||
blocks.forEach((block) => {
|
blocks.forEach((block) => {
|
||||||
// only add button if browser supports Clipboard API
|
// only add button if browser supports Clipboard API
|
||||||
if (navigator.clipboard) {
|
|
||||||
let button = document.createElement("button");
|
let button = document.createElement("button");
|
||||||
|
|
||||||
button.innerText = copyButtonLabel;
|
button.innerText = copyButtonLabel;
|
||||||
block.appendChild(button);
|
block.parentNode.insertBefore(button, block);
|
||||||
|
|
||||||
button.addEventListener("click", async (event) => {
|
button.addEventListener("click", async (event) => {
|
||||||
await copyCode(block, event.target);
|
await copyCode(block, event.target);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function copyCode(block, button) {
|
async function copyCode(block, button) {
|
||||||
let code = block.querySelector("code");
|
let code = block.querySelector("code");
|
||||||
|
|
Loading…
Reference in a new issue