SuperAPI AI Directory

md-to-wechat

General & other

View repository

Updated 10-16 06:51

About this skill

Markdown to WeChat Official Account format & one-click publishing

Convert Markdown articles into rich-text HTML that can be pasted directly into the WeChat Official Account editor, with elegant and polished layout, and correct rendering of elements such as code highlighting, tables, and table of contents. Supports one-click draft creation/publishing to WeChat Official Account via API.

Quick Start

Install Dependencies

# 格式转换依赖
pip install markdown pygments beautifulsoup4

# 一键发布依赖(可选,仅发布时需要)
pip install requests

# 更好的默认封面图(可选)
pip install Pillow

Format Conversion (Single Article)

python ~/.cursor/skills/md-to-wechat/scripts/convert.py input.md

Parameter Description:

Parameter Description Default Value
input.md Path to the input Markdown file Required
-o output.html Path to the output HTML file {input}_wechat.html
--theme Theme Style:blue / green / dark / warm blue
--dir Batch Conversion: Specify a directory path -

Batch Conversion (Whole Directory)

# 转换目录下所有 .md 文件
python ~/.cursor/skills/md-to-wechat/scripts/convert.py --dir ./articles

# 批量转换,指定主题
python ~/.cursor/skills/md-to-wechat/scripts/convert.py --dir ./articles --theme green

One-Click Publishing - Configuration (First Time)

# 首次使用:配置 AppID 和 AppSecret
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --setup

Need to obtain from the WeChat Official Account Platform:

  1. Go to the Official Account backend → Settings and Development → Basic Configuration
  2. Obtain AppID and AppSecret
  3. Add this machine's IP to the IP whitelist

One-Click Publishing (Single Article)

# 创建草稿(推荐,可在公众号后台检查后手动发布)
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md

# 创建草稿并直接发布
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md --publish

# 指定标题、作者和封面图
python ~/.cursor/skills/md-to-wechat/scripts/publish.py input.md --title "文章标题" --author "作者" --thumb cover.jpg

Batch Publishing (Whole Directory)

# 批量创建草稿
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles

# 批量创建草稿并发布
python ~/.cursor/skills/md-to-wechat/scripts/publish.py --dir ./articles --publish

# 批量操作,自定义间隔(默认60s)
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 the draft No (create draft only)
--title Article title Automatically extracted from h1
--author Article author Empty
--thumb Cover image path (900x500+ recommended) Automatically generate a default cover
--theme Article theme style blue
--dir Batch operation: Specify a directory path -
--delay Interval in seconds between operations for each article (to prevent rate limiting) 60

Usage Workflow

Method 1: Preview + Manual Paste

  1. Run the conversion command to generate the HTML file
  2. Open the generated HTML file in a browser
  3. Click the "Copy content to clipboard" button at the top of the page
  4. In the WeChat Official Account backend editor, Ctrl+V paste it

Method 2: API One-Click Draft Creation (Recommended)

  1. For first-time use, run --setup to configure credentials
  2. Run the publishing command, and the script will automatically create a draft
  3. Go to the Official Account backend to check the draft content, and after confirming, manually mass-send it

Method 3: API One-Click Publishing

  1. For first-time use, run --setup to configure credentials
  2. Run the --publish command, and the script will automatically create a draft and publish it
  3. Note: Articles published via APIwill not be pushed to followers, if you need to push them, please manually mass-send in the backend

Available Themes

  • blue (Elegant Blue): Blue palette, professional and concise, suitable for technical/business articles
  • green (Fresh Green): Green palette, natural and fresh, suitable for lifestyle/popular science articles
  • dark (Classic Black): Black palette, steady and grand, suitable for in-depth/academic articles
  • warm (Warm Orange): Orange palette, lively and warm, suitable for marketing/story articles

Supported Markdown elements

  • Headings (h1-h4), with decorative styles
  • Paragraphs, justified
  • Bold、Italic、Strikethrough
  • Ordered/unordered lists, including nesting
  • Code blocks (with syntax highlighting and language labels)
  • Inline code
  • Tables (with zebra striping)
  • Blockquotes
  • Horizontal rules
  • Images (centered and adaptive, automatically uploaded to the WeChat material library)
  • Footnotes
  • Task lists

Notes

  • The WeChat editor does not support external link navigation; links will be displayed as underlined text
  • When publishing with one click, external images in the article will be automatically uploaded to the WeChat material library
  • In manual paste mode, images need to be uploaded to the WeChat material library first
  • All styles are inline CSS, ensuring they are fully preserved in the WeChat editor
  • Code blocks automatically scroll horizontally on mobile
  • The first publish requires configuring AppID/AppSecret and adding the IP to the whitelist
  • The access_token is valid for 2 hours; the script automatically caches and refreshes it
  • Articles published via the API will not appear in followers' subscription messages and need to be mass-sent manually
  • Starting in July 2025, publishing API permissions will be revoked for personal/uncertified accounts