diff --git a/lightrag/api/static/index.html b/lightrag/api/static/index.html index 04bdd84c..7865d6e7 100644 --- a/lightrag/api/static/index.html +++ b/lightrag/api/static/index.html @@ -384,6 +384,43 @@ } }); + function addCopyButtons() { + // Adds a copy button to all code tags + document.querySelectorAll('pre').forEach(pre => { + if (!pre.querySelector('.copy-button')) { + const button = document.createElement('button'); + button.className = 'copy-button absolute top-2 right-2 p-2 bg-slate-700 text-white rounded-md opacity-0 group-hover:opacity-100 transition-opacity'; + button.innerHTML = ` + + `; + + pre.style.position = 'relative'; + pre.classList.add('group'); + + button.addEventListener('click', () => { + navigator.clipboard.writeText(pre.querySelector('code').textContent); + button.innerHTML = ` + + `; + setTimeout(() => { + button.innerHTML = ` + + `; + }, 2000); + }); + + pre.appendChild(button); + } + }); + } queryForm.addEventListener('submit', async (e) => { e.preventDefault(); @@ -451,6 +488,8 @@ queryResponse.innerHTML = '
No response data received
'; } + // Call this after loading markdown content + addCopyButtons(); // Optional: Add sources if available if (data.sources && data.sources.length > 0) { const sourcesHtml = `