Markdown 导出 HTML:把文档变成独立网页
Markdown 不只能看预览——导成 HTML,它就是一个能离线打开、随处分享的网页。这篇讲清为什么导、怎么导、以及样式和图片怎么不丢。
Markdown 匯出 HTML:把文件變成獨立網頁
Markdown 不只會看預覽——匯成 HTML,它就是一個能離線打開、隨處分享的網頁。這篇講清為什麼匯、怎麼匯、以及樣式和圖片怎麼不丟。
Markdown to HTML: Turn Docs into Standalone Web Pages
Markdown isn't just for preview—export it to HTML and it becomes a web page you can open offline and share anywhere. This article covers why, how, and how to keep styles and images intact.
一、导出 HTML 能干嘛
- 离线文档:导出的
.html双击就能在浏览器打开,不用装任何软件,发给谁都能看。 - 单页网站 / 落地页:产品介绍、活动页、个人简历,一份 Markdown 就生成好看的网页。
- 博客与文档站:很多静态博客(如本站的博客)本质就是把 Markdown 转成 HTML 发布。
- 存档与印刷:HTML 配合打印样式,一键存成 PDF,长期保存不乱。
二、三种常用方法
1. 编辑器自带导出(最省事)
像 365Lab、Typora 这类工具,顶栏“导出 → HTML”就下载一个自带样式的文件。365Lab 导出的 HTML 已内嵌样式,离线也不走样。
2. 用 Pandoc 命令行
pandoc note.md -o note.html --embed-resources --standalone
--embed-resources 会把 CSS、图片一起打进文件,发给别人也能看。
3. 在线转换
不少免费站点支持粘贴 Markdown 直接出 HTML,适合偶尔用、不想装软件的时候。
三、样式与图片怎么随文件走
导出最容易出的问题是“在我电脑上好看,发给你就裸了”。两个要点:
- 样式内嵌:选“自包含 / standalone / embed”选项,把 CSS 写进 HTML 里,而不是引用一个外部
.css。否则换台电脑样式就丢了。 - 图片内联或用相对路径:小图可转成 base64 内嵌;大图或图床图,把图片和 HTML 放同目录用相对路径(见 Markdown 插入图片)。
判断标准:把导出的 .html 单独拷到一个空文件夹、断网打开,如果样式和图片都还在,才算“真正随文件走”。
四、做成单页网站的两种去处
导出的 HTML 想上线,最省心的是静态托管:
- Cloudflare Pages / GitHub Pages / Netlify:把 HTML 拖上去就给一个公网地址,免费、全球加速。
- 对象存储 + CDN:适合要自定义域名、长期运行的页面。
本博客本身就用 Cloudflare Pages 托管,零服务器、纯静态,维护成本几乎为零。
五、3 个容易翻车的点
1. 外部 CSS 没一起发
如上所述,务必用内嵌样式再分享。
2. 图片是绝对路径
 这种路径换电脑必挂,改成相对路径或外链。
3. 中文编码乱码
保存时选 UTF-8,HTML 头部保留 <meta charset="UTF-8">,中文才不会变乱码方块。
六、常见问题
Q:导出的 HTML 能再编辑吗?
A:HTML 回到编辑器就难了。正确流程是“改 Markdown 源文件,再重新导出”,源文件永远留着。
Q:和直接存 PDF 比,HTML 好在哪?
A:HTML 能交互、能响应式、能继续改样式;PDF 更适合定稿打印。两者都能从同一份 Markdown 生成,见 Markdown 转 PDF。
Q:想变成 Word 怎么办?
A:先用 Markdown 转 Word 的方案(Markdown 转 Word),或在导出的 HTML 里“另存为 .docx”。
Q:哪里能一站式导出?
A:打开 365Lab 在线编辑器,写好之后顶栏导出 HTML,内嵌样式、免注册。
从零上手看 Markdown 是什么?10 分钟上手指南;要做更多格式转换,见 转 PDF 与 转 Word。要发布成网站,看 Markdown + GitHub Pages 免费建站。
一、匯出 HTML 能幹嘛
- 離線文件:匯出的
.html雙擊就能在瀏覽器打開,不用裝任何軟體,發給誰都能看。 - 單頁網站 / 落地頁:產品介紹、活動頁、個人履歷,一份 Markdown 就生成好看的網頁。
- 部落格與文件站:很多靜態部落格(如本站的部落格)本質就是把 Markdown 轉成 HTML 發布。
- 封存與印刷:HTML 配合列印樣式,一鍵存成 PDF,長期保存不亂。
二、三種常用方法
1. 編輯器自帶匯出(最省事)
像 365Lab、Typora 這類工具,頂欄「匯出 → HTML」就下載一個自帶樣式的檔案。365Lab 匯出的 HTML 已內嵌樣式,離線也不走樣。
2. 用 Pandoc 命令列
pandoc note.md -o note.html --embed-resources --standalone
--embed-resources 會把 CSS、圖片一起打進檔案,發給別人也能看。
3. 線上轉換
不少免費站點支援貼上 Markdown 直接出 HTML,適合偶爾用、不想裝軟體的時候。
三、樣式與圖片怎麼隨文件走
匯出最容易出的問題是「在我電腦上好看,發給你就裸了」。兩個要點:
- 樣式內嵌:選「自包含 / standalone / embed」選項,把 CSS 寫進 HTML 裡,而不是引用一個外部
.css。否則換台電腦樣式就丟了。 - 圖片內聯或用相對路徑:小圖可轉成 base64 內嵌;大圖或圖床圖,把圖片和 HTML 放同目錄用相對路徑(見 Markdown 插入圖片)。
判斷標準:把匯出的 .html 單獨拷到一個空資料夾、斷網打開,如果樣式和圖片都還在,才算「真正隨文件走」。
四、做成單頁網站的兩種去處
匯出的 HTML 想上線,最省心的是靜態託管:
- Cloudflare Pages / GitHub Pages / Netlify:把 HTML 拖上去就給一個公網地址,免費、全球加速。
- 物件儲存 + CDN:適合要自訂網域、長期運行的頁面。
本部落格本身就用 Cloudflare Pages 託管,零伺服器、純靜態,維護成本幾乎為零。
五、3 個容易翻車的點
1. 外部 CSS 沒一起發
如上所述,務必用內嵌樣式再分享。
2. 圖片是絕對路徑
 這種路徑換電腦必掛,改成相對路徑或外鏈。
3. 中文編碼亂碼
儲存時選 UTF-8,HTML 頭部保留 <meta charset="UTF-8">,中文才不會變亂碼方塊。
六、常見問題
Q:匯出的 HTML 能再編輯嗎?
A:HTML 回到編輯器就難了。正確流程是「改 Markdown 源檔,再重新匯出」,源檔永遠留著。
Q:和直接存 PDF 比,HTML 好在哪?
A:HTML 能互動、能響應式、能繼續改樣式;PDF 更適合定稿列印。兩者都能從同一份 Markdown 生成,見 Markdown 轉 PDF。
Q:想變成 Word 怎麼辦?
A:先用 Markdown 轉 Word 的方案(Markdown 轉 Word),或在匯出的 HTML 裡「另存為 .docx」。
Q:哪裡能一站式匯出?
A:打開 365Lab 線上編輯器,寫好之後頂欄匯出 HTML,內嵌樣式、免註冊。
從零上手看 Markdown 是什麼?10 分鐘上手指南;要做更多格式轉換,見 轉 PDF 與 轉 Word。要發佈成網站,看 Markdown + GitHub Pages 免費建站。
1. What exporting to HTML is good for
- Offline docs: the exported
.htmlopens in any browser with a double-click—no software needed, and anyone you send it to can view it. - Single-page site / landing page: product intros, event pages, personal résumés—one Markdown file generates a good-looking page.
- Blogs and doc sites: many static blogs (like this one) are essentially Markdown converted to HTML and published.
- Archiving and printing: with print styles, HTML exports to PDF in one click and stays tidy for long-term storage.
2. Three common methods
1. Built-in editor export (easiest)
Tools like 365Lab and Typora offer "Export → HTML" in the top bar and download a styled file. 365Lab's exported HTML has styles inlined, so it looks right offline too.
2. Pandoc from the command line
pandoc note.md -o note.html --embed-resources --standalone
--embed-resources bundles CSS and images into the file, so recipients can view it too.
3. Online conversion
Many free sites let you paste Markdown and get HTML directly—handy for occasional use when you don't want to install anything.
3. How styles and images travel with the file
The most common export problem is "looks great on my machine, but bare on yours." Two key points:
- Inline the styles: choose the "self-contained / standalone / embed" option to write CSS into the HTML rather than linking an external
.css. Otherwise styles vanish on another machine. - Inline images or use relative paths: small images can be base64-inlined; for large or hosted images, keep them in the same folder as the HTML using relative paths (see Inserting images in Markdown).
Test: copy the exported .html alone into an empty folder, open it offline, and if styles and images are still there, it truly travels with the file.
4. Two homes for a single-page site
To put the exported HTML online, the easiest is static hosting:
- Cloudflare Pages / GitHub Pages / Netlify: drag the HTML up and get a public URL—free, globally accelerated.
- Object storage + CDN: good for pages that need a custom domain and run long-term.
This very blog is hosted on Cloudflare Pages: zero servers, pure static, almost no maintenance cost.
5. 3 common pitfalls
1. External CSS wasn't sent along
As above, always share with inlined styles.
2. Images use absolute paths
A path like  breaks on another machine—switch to relative paths or external links.
3. Chinese shows up as mojibake
Save as UTF-8 and keep <meta charset="UTF-8"> in the HTML head, so Chinese doesn't turn into garbage blocks.
6. FAQ
Q: Can exported HTML be edited again?
A: Once HTML goes back into an editor it's messy. The right flow is "edit the Markdown source, then re-export"—always keep the source.
Q: How is HTML better than just saving a PDF?
A: HTML is interactive, responsive, and restyleable; PDF is better for finalized printing. Both come from the same Markdown—see Markdown to PDF.
Q: What if I want a Word file?
A: Use a Markdown-to-Word method first (Markdown to Word), or "Save as .docx" from the exported HTML.
Q: Where can I do it all in one place?
A: Open the 365Lab online editor, write, then export HTML from the top bar—inlined styles, no sign-up.
To start from zero, see What Is Markdown? A 10-Minute Guide; for more format conversions, see to PDF and to Word. To publish as a site, see Markdown + GitHub Pages: free hosting.