md-to-wechat
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown 转微信公众号格式 & 一键发布
Markdown to WeChat Official Account Format & One-Click Publishing
将 Markdown 文章转换为微信公众号编辑器可直接粘贴的富文本 HTML,排版美观大方,代码高亮、表格、目录等元素均正确渲染。支持通过 API 一键创建草稿/发布到微信公众号。
Convert Markdown articles to rich-text HTML that can be directly pasted into the WeChat Official Account editor, with beautiful typesetting. Elements like code highlighting, tables, and directories are rendered correctly. Supports one-click draft creation/publishing to WeChat Official Account via API.
快速使用
Quick Start
依赖安装
Dependency Installation
bash
undefinedbash
undefined格式转换依赖
Format conversion dependencies
pip install markdown pygments beautifulsoup4
pip install markdown pygments beautifulsoup4
一键发布依赖(可选,仅发布时需要)
One-click publishing dependencies (optional, required only for publishing)
pip install requests
pip install requests
更好的默认封面图(可选)
Better default cover image (optional)
pip install Pillow
undefinedpip install Pillow
undefined格式转换(单篇)
Format Conversion (Single Article)
bash
python ~/.cursor/skills/md-to-wechat/scripts/convert.py input.md参数说明:
| 参数 | 说明 | 默认值 |
|---|---|---|
| 输入的 Markdown 文件路径 | 必填 |
| 输出 HTML 文件路径 | |
| 主题风格: | |
| 批量转换:指定目录路径 | - |
bash
python ~/.cursor/skills/md-to-wechat/scripts/convert.py input.mdParameter Description:
| Parameter | Description | Default Value |
|---|---|---|
| Path of the input Markdown file | Required |
| Path of the output HTML file | |
| Theme style: | |
| Batch conversion: specify directory path | - |
批量转换(整个目录)
Batch Conversion (Entire Directory)
bash
undefinedbash
undefined转换目录下所有 .md 文件
Convert all .md files in the directory
python ~/.cursor/skills/md-to-wechat/scripts/convert.py --dir ./articles
python ~/.cursor/skills/md-to-wechat/scripts/convert.py --dir ./articles
批量转换,指定主题
Batch conversion with specified theme
python ~/.cursor/skills/md-to-wechat/scripts/convert.py --dir ./articles --theme green
undefinedpython ~/.cursor/skills/md-to-wechat/scripts/convert.py --dir ./articles --theme green
undefined一键发布 - 配置(首次)
One-Click Publishing - Configuration (First Use)
bash
undefinedbash
undefined首次使用:配置 AppID 和 AppSecret
First use: configure AppID and AppSecret
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --setup
需要在微信公众平台获取:
1. 进入 **公众号后台 → 设置与开发 → 基本配置**
2. 获取 **AppID** 和 **AppSecret**
3. 将本机 IP 添加到 **IP 白名单**python ~/.cursor/skills/md-to-wechat/scripts/publish.py --setup
You need to obtain the following from WeChat Official Account Platform:
1. Go to **Official Account Backend → Settings & Development → Basic Configuration**
2. Get **AppID** and **AppSecret**
3. Add your local IP to the **IP Whitelist**一键发布(单篇)
One-Click Publishing (Single Article)
bash
undefinedbash
undefined创建草稿(推荐,可在公众号后台检查后手动发布)
Create draft (recommended, check and publish manually in official account backend)
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md
创建草稿并直接发布
Create draft and publish directly
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md --publish
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md --publish
指定标题、作者和封面图
Specify title, author and cover image
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md --title "文章标题" --author "作者" --thumb cover.jpg
undefinedpython ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md --title "Article Title" --author "Author" --thumb cover.jpg
undefined批量发布(整个目录)
Batch Publishing (Entire Directory)
bash
undefinedbash
undefined批量创建草稿
Batch create drafts
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles
批量创建草稿并发布
Batch create drafts and publish
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles --publish
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles --publish
批量操作,自定义间隔(默认60s)
Batch operation with custom interval (default 60s)
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles --delay 30
**发布参数说明:**
| 参数 | 说明 | 默认值 |
|------|------|--------|
| `--setup` | 配置 AppID/AppSecret | - |
| `--publish` | 创建草稿后直接发布 | 否(仅创建草稿) |
| `--title` | 文章标题 | 自动从 h1 提取 |
| `--author` | 文章作者 | 空 |
| `--thumb` | 封面图片路径(建议 900x500+) | 自动生成默认封面 |
| `--theme` | 文章主题风格 | `blue` |
| `--dir` | 批量操作:指定目录路径 | - |
| `--delay` | 每篇文章操作间隔秒数(防限流) | `60` |python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles --delay 30
**Publishing Parameter Description:**
| Parameter | Description | Default Value |
|-----------|-------------|---------------|
| `--setup` | Configure AppID/AppSecret | - |
| `--publish` | Publish directly after creating draft | No (only create draft) |
| `--title` | Article title | Automatically extracted from h1 |
| `--author` | Article author | Empty |
| `--thumb` | Cover image path (recommended 900x500+) | Automatically generate default cover |
| `--theme` | Article theme style | `blue` |
| `--dir` | Batch operation: specify directory path | - |
| `--delay` | Interval between operations per article (to prevent rate limiting) | `60` |使用流程
Usage Workflow
方式一:预览 + 手动粘贴
Method 1: Preview + Manual Paste
- 执行转换命令,生成 HTML 文件
- 用浏览器打开生成的 HTML 文件
- 点击页面顶部「复制内容到剪贴板」按钮
- 在微信公众号后台编辑器中 粘贴即可
Ctrl+V
- Execute the conversion command to generate HTML file
- Open the generated HTML file with a browser
- Click the "Copy content to clipboard" button at the top of the page
- Paste with in the WeChat Official Account backend editor
Ctrl+V
方式二:API 一键创建草稿(推荐)
Method 2: One-Click Draft Creation via API (Recommended)
- 首次使用先运行 配置凭据
--setup - 执行发布命令,脚本自动创建草稿
- 前往公众号后台检查草稿内容,确认后手动群发
- Run to configure credentials for first use
--setup - Execute the publishing command, the script will automatically create a draft
- Go to the official account backend to check the draft content, then manually send it after confirmation
方式三:API 一键发布
Method 3: One-Click Publishing via API
- 首次使用先运行 配置凭据
--setup - 执行 命令,脚本自动创建草稿并发布
--publish - 注意:API 发布的文章不会推送给粉丝,如需推送请在后台手动群发
- Run to configure credentials for first use
--setup - Execute the command, the script will automatically create a draft and publish it
--publish - Note: Articles published via API will not be pushed to followers, please manually send them in the backend if needed
可用主题
Available Themes
- blue (优雅蓝):蓝色系,专业简洁,适合技术/商务文章
- green (清新绿):绿色系,自然清新,适合生活/科普文章
- dark (经典黑):黑色系,沉稳大气,适合深度/学术文章
- warm (温暖橙):橙色系,活泼温暖,适合营销/故事文章
- blue (Elegant Blue): Blue-themed, professional and concise, suitable for technical/business articles
- green (Fresh Green): Green-themed, natural and fresh, suitable for life/science popularization articles
- dark (Classic Black): Black-themed, calm and grand, suitable for in-depth/academic articles
- warm (Warm Orange): Orange-themed, lively and warm, suitable for marketing/story articles
支持的 Markdown 元素
Supported Markdown Elements
- 标题 (h1-h4),带装饰样式
- 段落,两端对齐
- 加粗、斜体、
删除线 - 有序/无序列表,含嵌套
- 代码块(带语法高亮和语言标签)
- 行内代码
- 表格(带斑马纹)
- 引用块
- 分割线
- 图片(居中自适应,自动上传到微信素材库)
- 脚注
- 任务列表
- Headings (h1-h4) with decorative styles
- Paragraphs with justified alignment
- Bold, italic,
strikethrough - Ordered/unordered lists, including nested lists
- Code blocks (with syntax highlighting and language tags)
- Inline code
- Tables (with zebra stripes)
- Blockquotes
- Horizontal rules
- Images (centered and adaptive, automatically uploaded to WeChat material library)
- Footnotes
- Task lists
注意事项
Notes
- 微信编辑器不支持外部链接跳转,链接会显示为带下划线的文字
- 一键发布时,文章内的外部图片会自动上传到微信素材库
- 手动粘贴模式下,图片需要先上传到微信素材库
- 所有样式均为内联 CSS,确保在微信编辑器中完整保留
- 代码块在移动端会自动横向滚动
- 首次发布需要配置 AppID/AppSecret 并将 IP 加入白名单
- access_token 有效期 2 小时,脚本会自动缓存和刷新
- 通过 API 发布的文章不会出现在粉丝的订阅消息中,需手动群发
- 2025年7月起,个人主体/未认证账号将被回收发布接口权限
- WeChat editor does not support external link jumps, links will be displayed as underlined text
- When using one-click publishing, external images in the article will be automatically uploaded to WeChat material library
- In manual paste mode, images need to be uploaded to WeChat material library first
- All styles are inline CSS to ensure complete retention in WeChat editor
- Code blocks will automatically scroll horizontally on mobile devices
- First-time publishing requires configuring AppID/AppSecret and adding IP to whitelist
- access_token is valid for 2 hours, the script will automatically cache and refresh it
- Articles published via API will not appear in followers' subscription messages, manual sending is required
- Starting from July 2025, publishing interface permissions will be revoked for personal accounts/unverified accounts