|
29 | 29 | background-color: #f5f5f5; |
30 | 30 | font-size: 16px; |
31 | 31 | font-family: Helvetica, Arial, sans-serif; |
| 32 | + overflow: auto; |
32 | 33 | } |
33 | 34 |
|
34 | 35 | #output-container { |
@@ -93,7 +94,7 @@ <h1>Rich text HTML extractor</h1> |
93 | 94 | <p>Copy formatted text from a webpage and paste here to extract the HTML:</p> |
94 | 95 |
|
95 | 96 | <div id="paste-area" contenteditable="true"></div> |
96 | | - <p class="info-text">Paste using Ctrl+V or ⌘+V to capture the rich text HTML</p> |
| 97 | + <p class="info-text">Paste using Ctrl+V or ⌘+V to capture the rich text HTML. For best results on Windows, try pasting into word processors first.</p> |
97 | 98 |
|
98 | 99 | <div id="output-container"> |
99 | 100 | <h2>HTML code</h2> |
@@ -129,26 +130,25 @@ <h2>Preview</h2> |
129 | 130 |
|
130 | 131 | // Handle paste event to capture HTML |
131 | 132 | pasteArea.addEventListener('paste', function(e) { |
132 | | - // Get HTML data from clipboard |
133 | | - const clipboardData = e.clipboardData || window.clipboardData; |
134 | | - const pastedHtml = clipboardData.getData('text/html'); |
135 | | - |
136 | | - if (pastedHtml) { |
137 | | - // Prevent default paste |
138 | | - e.preventDefault(); |
139 | | - |
140 | | - // Display the HTML code with escaped characters |
141 | | - htmlOutput.value = pastedHtml; |
142 | | - |
143 | | - // Show the output container |
144 | | - outputContainer.style.display = 'block'; |
145 | | - |
146 | | - // Show preview of how the HTML renders |
147 | | - previewContent.innerHTML = pastedHtml; |
| 133 | + // Let the paste happen normally first |
| 134 | + setTimeout(() => { |
| 135 | + // Get current HTML content after the paste |
| 136 | + const pastedContent = pasteArea.innerHTML; |
148 | 137 |
|
149 | | - // Let user know paste was successful |
150 | | - pasteArea.innerHTML = '<p style="color: green;">Content pasted. HTML extracted.</p>'; |
151 | | - } |
| 138 | + if (pastedContent) { |
| 139 | + // Display the HTML code with escaped characters |
| 140 | + htmlOutput.value = pastedContent; |
| 141 | + |
| 142 | + // Show the output container |
| 143 | + outputContainer.style.display = 'block'; |
| 144 | + |
| 145 | + // Show preview of how the HTML renders |
| 146 | + previewContent.innerHTML = pastedContent; |
| 147 | + |
| 148 | + // Let user know paste was successful |
| 149 | + pasteArea.innerHTML = '<p style="color: green;">Content pasted. HTML extracted.</p>'; |
| 150 | + } |
| 151 | + }, 0); |
152 | 152 | }); |
153 | 153 |
|
154 | 154 | // Reset paste area when clicked |
|
0 commit comments