mirror of
https://github.com/sune-org/sune.git
synced 2026-09-18 04:45:42 +00:00
Fix: Use robust copy fallback in code blocks
Co-authored-by: gemini-3.7-flash <noreply@google.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import mathjax3 from 'https://esm.sh/markdown-it-mathjax3';
|
||||
import { copyToClipboard } from './utils.js';
|
||||
|
||||
export const md = window.md = window.markdownit({ html: false, linkify: true, typographer: true, breaks: true }).use(mathjax3);
|
||||
|
||||
@@ -10,11 +11,10 @@ export function enhanceCodeBlocks(root, doHL = true) {
|
||||
const len = code.textContent.length, countText = len >= 1e3 ? (len / 1e3).toFixed(1) + 'K' : len;
|
||||
const $btn = window.$('<button class="bg-slate-900 text-white rounded-lg py-1 px-2 text-xs opacity-85">Copy</button>').on('click', async e => {
|
||||
e.stopPropagation();
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.innerText);
|
||||
if (await copyToClipboard(code.innerText)) {
|
||||
$btn.text('Copied');
|
||||
setTimeout(() => $btn.text('Copy'), 1200);
|
||||
} catch { }
|
||||
}
|
||||
});
|
||||
const $container = window.$('<div class="code-actions absolute top-2 right-2 flex items-center gap-2"></div>');
|
||||
$container.append(window.$(`<span class="text-xs text-gray-500">${countText} chars</span>`), $btn);
|
||||
|
||||
Reference in New Issue
Block a user