Markdown 预览工具

实时预览 Markdown 效果

`; const blob = new Blob([html], { type: 'text/html' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'document.html'; link.click(); URL.revokeObjectURL(url); } function clearMarkdown() { document.getElementById('markdownInput').value = ''; document.getElementById('preview').innerHTML = ''; } // Allow Tab key in textarea document.getElementById('markdownInput').addEventListener('keydown', function(e) { if (e.key === 'Tab') { e.preventDefault(); const start = this.selectionStart; const end = this.selectionEnd; this.value = this.value.substring(0, start) + '\t' + this.value.substring(end); this.selectionStart = this.selectionEnd = start + 1; } }); // Initialize with sample content const sampleMarkdown = `# Markdown 预览工具 ## 功能特性 - 📝 实时预览 Markdown 内容 - 💾 支持下载为 Markdown 或 HTML - ✨ 支持完整的 Markdown 语法 ## 代码示例 \`\`\`javascript function hello() { console.log('Hello, World!'); } \`\`\` ## 引用 > 这是一个引用块 > 可以包含多行内容 --- **粗体文本** 和 *斜体文本*`; document.getElementById('markdownInput').value = sampleMarkdown; updatePreview();