Terminal to HTML

Instructions: Paste terminal output below. Supports RTF (colored terminal output), HTML, or plain text.
Paste terminal output to see the HTML conversion
`; } pasteArea.addEventListener('paste', async (e) => { e.preventDefault(); const clipboardData = e.clipboardData; resultsDiv.innerHTML = ''; if (!clipboardData) { resultsDiv.innerHTML = '
No clipboard data detected
'; return; } let htmlOutput = ''; let fullHtml = ''; // Try to get HTML first const htmlData = clipboardData.getData('text/html'); if (htmlData) { // HTML is available, use it directly htmlOutput = htmlData; fullHtml = wrapInHtmlDocument(htmlData); } else { // Try RTF const rtfData = clipboardData.getData('text/rtf'); if (rtfData) { try { const result = rtfToHtml(rtfData); htmlOutput = result.html; const backgroundColor = result.backgroundColor; const defaultTextColor = result.defaultTextColor; let preStyle = ''; const styles = []; if (backgroundColor) { styles.push(`background: ${backgroundColor}`); } if (defaultTextColor) { styles.push(`color: ${defaultTextColor}`); } if (styles.length > 0) { preStyle = ` style="${styles.join('; ')}; padding: 15px; border-radius: 4px;"`; } fullHtml = wrapInHtmlDocument(`${htmlOutput}`); } catch (error) { resultsDiv.innerHTML = `
Error parsing RTF: ${error.message}
`; return; } } else { // Fall back to plain text const plainText = clipboardData.getData('text/plain'); if (plainText) { htmlOutput = escapeHtml(plainText); fullHtml = wrapInHtmlDocument(`
${htmlOutput}
`); } else { resultsDiv.innerHTML = '
No supported format detected in clipboard.
'; return; } } } // Create HTML code section const codeSection = document.createElement('div'); codeSection.className = 'section'; codeSection.innerHTML = `

HTML Code

`; resultsDiv.appendChild(codeSection); const copyHtmlBtn = document.getElementById('copyHtmlBtn'); const htmlOutputTextarea = document.getElementById('htmlOutput'); copyHtmlBtn.addEventListener('click', async () => { try { await navigator.clipboard.writeText(htmlOutputTextarea.value); copyHtmlBtn.textContent = 'Copied!'; copyHtmlBtn.classList.add('copied'); setTimeout(() => { copyHtmlBtn.textContent = 'Copy HTML'; copyHtmlBtn.classList.remove('copied'); }, 2000); } catch (err) { console.error('Failed to copy HTML:', err); } }); // Create preview section const previewSection = document.createElement('div'); previewSection.className = 'section'; previewSection.innerHTML = `

Preview

${fullHtml}
`; resultsDiv.appendChild(previewSection); }); // Clear the textarea on paste pasteArea.addEventListener('paste', () => { setTimeout(() => { pasteArea.value = ''; }, 0); });