📝 Markdown 编辑器

🏠 赛博魔盒0001F333 技能树 🛠 开发工具纯前端
📝 编辑Markdown
0 字0 行阅读 0 分钟
👁 预览
在此输入 Markdown 实时预览...
🛠 更多开发者工具:JSON格式化 · Base64 · 正则测试 · SQL格式化 · Diff对比 · GameDev →
'+preview.innerHTML+' ';const blob=new Blob([html],{type:'text/html'});const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download='markdown-export.html';a.click()} function loadSample(){input.value=`# 赛博魔盒 Markdown 编辑器\n\n欢迎使用!支持 **粗体**、*斜体*、~~删除线~~。\n\n## 功能特性\n\n- ✅ 实时预览\n- ✅ GitHub Flavored Markdown\n- ✅ 代码高亮\n- ✅ 表格支持\n- ✅ 导出 HTML\n\n## 代码示例\n\n\`\`\`javascript\nfunction hello() {\n console.log("Hello, CyberMagi!");\n}\n\`\`\`\n\n## 表格\n\n| 功能 | 状态 | 说明 |\n|------|------|------|\n| Markdown | ✅ | 完整支持 |\n| 导出 | ✅ | HTML格式 |\n| AI增强 | 🚧 | 即将上线 |\n\n> 赛博魔盒 — 免费AI工具集\n\n[访问官网](https://cybermagi.space)`;renderMD()} function clearAll(){input.value='';preview.innerHTML='在此输入 Markdown 实时预览...';document.getElementById('wordCount').textContent='0 字符';document.getElementById('lineCount').textContent='0 行'} loadSample(); function exportPDF(){ const w=window.open('','_blank','width=800,height=600'); w.document.write('Markdown Export '+preview.innerHTML+' '); w.document.close();setTimeout(()=>w.print(),500); } let autoSaveTimer; function autoSave(){clearTimeout(autoSaveTimer);autoSaveTimer=setTimeout(()=>{localStorage.setItem('cm_md_draft',input.value);document.getElementById('saveStatus').textContent='💾 已保存';setTimeout(()=>document.getElementById('saveStatus').textContent='',2000)},1000)} // Override renderMD to include stats and auto-save const origRenderMD=renderMD; renderMD=function(){ origRenderMD(); const chars=input.value.length; const words=input.value.replace(/[\u4e00-\u9fa5]/g,'x ').split(/\s+/).filter(Boolean).length; document.getElementById('wordCount').textContent=chars.toLocaleString()+' 字符'; document.getElementById('readTime').textContent='阅读 '+Math.max(1,Math.ceil(words/300))+' 分钟'; autoSave(); }; // Load draft on startup (function(){const d=localStorage.getItem('cm_md_draft');if(d&&d!==input.value){input.value=d;renderMD();document.getElementById('saveStatus').textContent='📂 已恢复';setTimeout(()=>document.getElementById('saveStatus').textContent='',2000)}})();