Spaces:
Running
Running
feat: Add copy markdown button with clipboard functionality
Browse files- index.html +1 -0
- script.js +11 -0
index.html
CHANGED
@@ -23,6 +23,7 @@
|
|
23 |
<label>
|
24 |
<input type="checkbox" id="enable-table-column-tracking"> Table column tracking
|
25 |
</label>
|
|
|
26 |
<button type="submit" class="bg-black px-3 text-white h-8 rounded-lg" form="converter-form">Convert to semantic markdown</button>
|
27 |
<a href="https://github.com/romansky/dom-to-semantic-markdown" target="_blank" class="underline ml-auto">Github</a>
|
28 |
</div>
|
|
|
23 |
<label>
|
24 |
<input type="checkbox" id="enable-table-column-tracking"> Table column tracking
|
25 |
</label>
|
26 |
+
<button id="copy-markdown" class="bg-black px-3 text-white h-8 rounded-lg" disabled>Copy markdown</button>
|
27 |
<button type="submit" class="bg-black px-3 text-white h-8 rounded-lg" form="converter-form">Convert to semantic markdown</button>
|
28 |
<a href="https://github.com/romansky/dom-to-semantic-markdown" target="_blank" class="underline ml-auto">Github</a>
|
29 |
</div>
|
script.js
CHANGED
@@ -1,5 +1,15 @@
|
|
1 |
const { convertHtmlToMarkdown } = htmlToSMD;
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
// Handle toggle between URL and HTML input
|
4 |
document.getElementById("input-html-toggle").addEventListener("change", function(e) {
|
5 |
const urlInput = document.getElementById("url-input");
|
@@ -73,6 +83,7 @@ document
|
|
73 |
// Convert HTML to Markdown
|
74 |
const markdown = await convertHtmlToMarkdown(htmlContent, options);
|
75 |
markdownOutput.textContent = markdown;
|
|
|
76 |
} catch (error) {
|
77 |
markdownOutput.textContent = "Error: " + error.message;
|
78 |
}
|
|
|
1 |
const { convertHtmlToMarkdown } = htmlToSMD;
|
2 |
|
3 |
+
// Handle copy markdown button
|
4 |
+
document.getElementById("copy-markdown").addEventListener("click", async function() {
|
5 |
+
const markdownOutput = document.getElementById("markdown-output");
|
6 |
+
try {
|
7 |
+
await navigator.clipboard.writeText(markdownOutput.textContent);
|
8 |
+
} catch (err) {
|
9 |
+
console.error('Failed to copy text: ', err);
|
10 |
+
}
|
11 |
+
});
|
12 |
+
|
13 |
// Handle toggle between URL and HTML input
|
14 |
document.getElementById("input-html-toggle").addEventListener("change", function(e) {
|
15 |
const urlInput = document.getElementById("url-input");
|
|
|
83 |
// Convert HTML to Markdown
|
84 |
const markdown = await convertHtmlToMarkdown(htmlContent, options);
|
85 |
markdownOutput.textContent = markdown;
|
86 |
+
document.getElementById("copy-markdown").disabled = false;
|
87 |
} catch (error) {
|
88 |
markdownOutput.textContent = "Error: " + error.message;
|
89 |
}
|