From 420e0cf863bdf7db0ca926c7164a774dfc2815d5 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 10 Jan 2025 16:12:56 +0000 Subject: [PATCH] feat: add copy button and consistent monospace font --- frontend/src/index.html | 53 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/frontend/src/index.html b/frontend/src/index.html index 92ff658..6c7d072 100644 --- a/frontend/src/index.html +++ b/frontend/src/index.html @@ -9,7 +9,7 @@ @@ -44,9 +67,14 @@

Document to Markdown Converter

Result
-
+
+
- +
@@ -78,6 +106,7 @@

Document to Markdown Converter

const rawMarkdown = document.getElementById('rawMarkdown'); const toggleViewBtn = document.getElementById('toggleViewBtn'); const downloadBtn = document.getElementById('downloadBtn'); + const copyButton = document.getElementById('copyButton'); // Toggle between rendered and raw markdown toggleViewBtn.addEventListener('click', () => { @@ -141,6 +170,24 @@

Document to Markdown Converter

// Create the initial drop zone HTML FileDropZone.createDropZone('dropZone'); + // Handle copy button + copyButton.addEventListener('click', async () => { + const textToCopy = rawMarkdown.textContent; + try { + await navigator.clipboard.writeText(textToCopy); + copyButton.classList.add('btn-success'); + setTimeout(() => { + copyButton.classList.remove('btn-success'); + }, 1000); + } catch (err) { + console.error('Failed to copy text:', err); + copyButton.classList.add('btn-error'); + setTimeout(() => { + copyButton.classList.remove('btn-error'); + }, 1000); + } + }); + // Handle download downloadBtn.addEventListener('click', () => { const markdown = rawMarkdown.textContent;