Add clipboard button to code blocks

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-11-06 18:38:11 +01:00
committed by Rūdolfs Ošiņš
parent 905b933e4a
commit 79b1e9c9f8
3 changed files with 28 additions and 0 deletions
+2
View File
@@ -1,3 +1,5 @@
<svelte:options customElement="radicle-clipboard" />
<script lang="ts" strictEvents>
import debounce from "lodash/debounce";
import { createEventDispatcher } from "svelte";
+23
View File
@@ -135,6 +135,12 @@
const treeChanges: Promise<void>[] = [];
for (const node of nodes) {
const preElement = node.parentElement as HTMLElement;
const copyButton = document.createElement("radicle-clipboard");
copyButton.setAttribute("text", node.textContent || "");
copyButton.setAttribute("small", "");
preElement.prepend(copyButton);
const className = Array.from(node.classList).find(name =>
name.startsWith(prefix),
);
@@ -196,6 +202,22 @@
border-bottom: 1px solid var(--color-border-hint);
}
.markdown :global(radicle-clipboard) {
display: none;
position: absolute;
right: 0.5rem;
top: 0.5rem;
}
.markdown :global(radicle-clipboard) {
background-color: var(--color-fill-ghost);
border-radius: var(--border-radius-small);
}
.markdown :global(pre:hover radicle-clipboard) {
display: flex;
}
.markdown :global(h3) {
font-size: calc(var(--font-size-medium) * 0.9);
font-weight: var(--font-weight-semibold);
@@ -268,6 +290,7 @@
}
.markdown :global(pre) {
position: relative;
font-family: var(--font-family-monospace);
font-size: var(--font-size-regular);
background-color: var(--color-fill-ghost);
+3
View File
@@ -2,4 +2,7 @@ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
export default {
preprocess: vitePreprocess(),
compilerOptions: {
customElement: true,
},
};