Markdown to WeChat Official Accounts: styles, code and links
Pasting raw Markdown or a standard HTML export into the WeChat Official Accounts editor (mp.weixin.qq.com) strips stylesheets, collapses code indentation, breaks blockquotes, and leaves external links unclickable. The reliable fix is to inline computed CSS rules and rewrite unsupported DOM nodes before copying, which MiaoYan's free browser Markdown viewer handles in one click (open /zh/tools/markdown-viewer/ and click 复制到公众号 when you also want external URLs turned into numbered end-references). Text, tables, code highlighting, task lists, and Mermaid diagrams arrive intact, while LaTeX formulas and local images need one extra check below.
Why strict rich-text editors break standard Markdown HTML
Web pages normally separate structure from presentation: a Markdown parser outputs <h2>, <blockquote>, and <pre><code class="hljs">, while a .css file supplies fonts and colors (covered in Markdown to HTML). WeChat's article editor runs a strict HTML sanitizer on ⌘V so pasted markup cannot break WeChat's mobile webview. Five sanitizer rules trip ordinary pastes:
- Every
<style>tag,<link rel="stylesheet">,class, andidattribute disappears, turning<span class="hljs-keyword">code tokens plain black unless RGB colors sit insidestyle="color: ...". - CSS pseudo-elements such as
blockquote::beforecannot travel on the clipboard, and WeChat applies its own grey border to<blockquote>tags unless they are retagged into<section>elements. - Arbitrary external
https://links do not open inside standard Official Account articles; onlymp.weixin.qq.comarticle links remain tappable. - Rich-text editors collapse runs of ASCII spaces and newlines inside
<pre><code>unless spaces become and line breaks become<br>. - Inline
<svg>diagrams and<input type="checkbox">controls get stripped, and KaTeX HTML spans cannot load external.woff2math fonts inside WeChat.
How MiaoYan's browser converter rewrites the DOM
MiaoYan's Markdown viewer renders your draft inside a sandboxed frame using the stylesheets, highlight.js grammars, and Mermaid theme from the Mac app. Clicking 复制到公众号 on /zh/tools/markdown-viewer/ (or Copy formatted on /tools/markdown-viewer/ for email and CMS editors that keep external links) clones the preview offscreen and runs six DOM passes before writing to your clipboard:
- It reads
getComputedStyleon every node, writes inherited typography (color,font-family,font-size,line-height,letter-spacing) where it differs from the parent alongside explicit boxmargin,padding,border, andbackground-color, then stripsclassandidattributes. - It measures MiaoYan's
blockquote::beforebar, converts it into an inlineborder-leftandpadding-left, and retags<blockquote>and the root container to<section>so WeChat's quote style never overrides it. - Inside
<pre>, tabs become four spaces, spaces turn into\u00a0( ), newlines become<br>with trailing empty breaks trimmed, andwhite-space: nowrap; overflow-x: autokeeps code horizontally scrollable on phones. - Every
.mermaid-image-container svgis drawn onto a<canvas>at 2x resolution and replaced with adata:image/png<img>locked to its display width for Retina clarity. - Task checkboxes become
`☑`and`☐`text spans, and nested<ul>or<ol>lists inside<li>move right after their parent item so indentation survives. - In WeChat mode (
/zh/tools/markdown-viewer/),https://mp.weixin.qq.com/links stay clickable, bare URLs stay plain text, and other externalhttporhttpslinks become inline text plus a superscript[n]marker with a 14px参考链接section appended at the end.
A step-by-step publishing workflow
- Draft your post in MiaoYan on Mac (
⌘\for split preview) or directly inside the browser editor, which supports⌘B,⌘I,⌘K,⌘E,⇧⌘E, and list continuation. - Run
Edit > Clean Typographyin MiaoYan on Mac, or paste into the Chinese typography cleaner to space Chinese and Latin words and fix half-width punctuation without touching code, URLs, or math; see Chinese-English spacing in Markdown notes. - Open
/zh/tools/markdown-viewer/, load your.mdfile, and toggle手机宽度(Phone width) to check heading wraps and table widths at 375px. - Click
复制到公众号, note how many external links moved to参考链接in the status line, and press⌘Vinsidemp.weixin.qq.com.
What goes wrong and how to fix it
LaTeX math shows as $...$ source text
Because clipboard HTML cannot embed KaTeX web fonts into WeChat, 复制到公众号 converts inline and display math back into <code>$...$</code> and <code>$$...$$</code> source text and notes that in the status bar rather than pasting broken boxes. For equation-heavy posts, export the section or full note as a 3x mobile PNG in Markdown to image; sizing details are in Markdown to image: export a note as a long PNG.
Local images are missing after paste
Browser tabs cannot read /i/screenshot.png from local disk, and WeChat blocks many hotlinked hosts on save. Either set up Settings > Editor > Upload to S3 or R2 in MiaoYan on Mac so screenshots get public https:// URLs WeChat can ingest on paste, or drag local PNGs from Finder straight into the WeChat editor afterward.
Dark-mode contrast and async diagrams
Always send a test preview (预览) to your phone with iOS or Android Dark Mode enabled. WeChat automatically inverts inline colors on dark screens; MiaoYan's warm paper palette (#403E3C ink with subtle quote and code fills) survives WeChat's inversion cleanly, whereas raw #000000 blocks turn harsh. Drafts stay in your browser's localStorage, or click 存进妙言 (Save to MiaoYan) on Mac to store the note in the GitHub or App Store app.
FAQ
Why do links to other WeChat articles stay clickable while GitHub links become footnotes?
WeChat Official Accounts permit inline links to https://mp.weixin.qq.com/ articles, so WeChat mode preserves those <a> tags and turns only external domains into numbered [1] end-references.
Does the browser tool upload my draft or images to a server?
No. Parsing, syntax highlighting, Mermaid rasterization, and CSS inlining run locally in your browser, and your draft stays only in localStorage on your device.
Can I use the same copy button for Substack, Ghost, or HTML email?
Use the English page at Markdown viewer and click Copy formatted. It runs the same inline CSS, <section> quote border, code spacing, and 2x PNG Mermaid steps while keeping external <a> links clickable.
Why did a Mermaid diagram fail to appear when I pasted immediately?
Mermaid loads on demand and renders asynchronously. Wait a second until the diagram finishes drawing in the preview pane before clicking 复制到公众号 so the canvas exporter can convert the SVG to PNG.
