Question formatting
This commit is contained in:
Vendored
+5
-3
@@ -26,8 +26,10 @@ export function replace(el, ...children) {
|
||||
el.replaceChildren();
|
||||
append(el, ...children);
|
||||
}
|
||||
const copyIcon = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"><rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2"/></svg>';
|
||||
const copiedIcon = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5l3.5 3.5L13 4.5"/></svg>';
|
||||
export function copyable(pre) {
|
||||
const button = h("button", { type: "button", class: "copy", title: "Copy to the clipboard" }, "copy");
|
||||
const button = h("button", { type: "button", class: "copy", title: "Copy to the clipboard", ariaLabel: "Copy to the clipboard", innerHTML: copyIcon });
|
||||
button.onclick = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(pre.textContent ?? "");
|
||||
@@ -36,9 +38,9 @@ export function copyable(pre) {
|
||||
void showAlert(errorText(err));
|
||||
return;
|
||||
}
|
||||
button.textContent = "copied";
|
||||
button.innerHTML = copiedIcon;
|
||||
setTimeout(() => {
|
||||
button.textContent = "copy";
|
||||
button.innerHTML = copyIcon;
|
||||
}, 1500);
|
||||
};
|
||||
return h("div", { class: "copyable" }, pre, button);
|
||||
|
||||
Reference in New Issue
Block a user