A general-purpose Markdown article typesetting and WeChat publishing tool that can turn any Markdown document / local manuscript / knowledge base note into a high-standard Official Account article with one click: multi-style exquisite typesetting, adaptive cover from the first image, and direct push to the WeChat Official Platform draft box .
Core capabilities and pipeline
flowchart TD
subgraph Input["1. 输入"]
A["任意 Markdown 文章 (.md / 文本)"] --> B["解析正文 & 提取首张图片"]
end
subgraph StyleEngine["2. 多风格排版引擎"]
B --> C{"选择风格 (--style)"}
C -->|默认| D1["Editorial 先锋大刊风 (editorial)\n- Didot/宋体 Retina 渐变透明标题图层\n- 88% 留白图片卡片\n- 墨蓝与橙金质感"]
C -->|可选| D2["阿芋·草木生活大刊风 (olive_artisan)\n- Bodoni 艺术数字 01/02\n- 黄绿胶带高亮大标题\n- 燕麦米灰软卡片"]
C -->|扩展| D3["可随时插拔新增更多风格"]
end
subgraph Publisher["3. 微信图床与草稿直推"]
D1 & D2 --> E["生成内联样式 HTML + 带一键复制预览页"]
B --> F["首图上传微信永久素材库作为头条封面 (thumb_media_id)"]
E --> G["正文图片自动上传微信 CDN (media/uploadimg) 替换 URL"]
F & G --> H["调用 draft/add 接口推送至公众号草稿箱"]
end
Publisher --> Output["手机微信收到草稿 ➔ 一键审核发布"]
---
## 工作模式与快速指令
### 0. 新手引导与配置模式(关键词:使用引导 / 怎么用 / 帮助 / 新手)
> **触发条件**:当用户输入包含 **「使用引导」**、**「怎么用」**、**「新手」**、**「帮助」**、**「API配置」**,或初次唤起且未提供文章时:
> **Agent 行为**:**必须直接输出以下结构化新手引导**,无需索要文章或报错。
**引导输出结构**:
1. **这是什么**:一键将 Markdown 转化为高颜值大刊排版、提取正文首图为头条封面并直推微信公众平台草稿箱;
2. **如何获取微信 API(5 步配置法)**:
- 访问微信开发者平台:`https://developers.weixin.qq.com/` 扫码登录;
- 首页下方找到 **「我的业务」** 中的对应公众号;
- 点击进入 **「基础能力」➔「开发秘钥」**,复制 `AppID` 并生成保存 `AppSecret`;
- 同区域找到 **「IP 白名单」**,将当前电脑公网 IP(终端运行 `curl cip.cc`)添加进去;
- 在技能目录下的 `wechat_config.json` 填入 `app_id` 和 `app_secret`。
3. **免 API 纯复制模式(立刻能用)**:
- 若暂未配置 API,也可以直接发文章给技能,系统会自动生成带「一键复制到公众号」悬浮栏的本地 `_预览.html`,浏览器打开点一下即可无损粘贴进后台;
4. **下一步操作示范**:
- 给用户 2 个可直接点击/复制发送的体验指令:
- *“帮我用大刊风排版示例文章:`examples/sample_editorial_article.md`”*
- *“这是我的文章草稿:[粘贴文字],帮我排版并推送到草稿箱”*
---
### 1. 默认大刊排版并直推微信草稿箱
直接向 Agent 发送指令或使用快捷命令:
```text
/sqsl-article-to-wechat 帮我把这篇文章排版并推送到公众号:[路径/内容]
or
/文章发公众号 把 docs/my_post.md 排版发到微信草稿箱。
Agent automatic execution flow:
- Parse the Markdown content and extract the article'sfirst image;
- Run
render_wechat_html.py, using Avant-Garde Large-Format style (editorial) to render inline-style HTML and preview files; - Run
wechat_draft_publisher.py:- Upload the extractedbody first imageautomatically to the WeChat material library as a 900×383 headline cover;
- Automatically upload all illustrations in the body to the WeChat image hosting service and replace them with
mmbiz.qpic.cnlinks; - Push to the WeChat Official Account draft box (output draft Media ID);
- At the same time, output a local preview HTML with "one-click copy to Official Account", making it convenient for manual preview and manual copy as a backup.
2. Specify different typesetting styles
You can use --style to specify the typesetting style:
editorial(default): Avant-Garde Large-Format style (Didot serif large watermark + Chinese Songti title layer, 88% whitespace illustrations, key quote cards);olive_artisan: A-Yu · Vegetation Mountain Wilderness Lifestyle Large-Format style (Bodoni artistic numerals 01/02, yellow-green tape-highlighted large headlines, warm oatmeal beige soft cards, 1.8 breathing line height).
For example:
/sqsl-article-to-wechat 用 olive_artisan 风格排版 docs/post.md
3. Command-line script invocation
Typesetting and publishing can also be run directly in the terminal via scripts:
(1) Generate only typeset HTML and preview page
python3 scripts/render_wechat_html.py "文章路径.md" --style editorial
Output:文章名_微信排版.html(pure inline-style version) and 文章名_预览.html(browser preview version with a one-click copy button).
(2) Direct push to WeChat draft box (automatically extract first image as cover)
python3 scripts/wechat_draft_publisher.py "文章名_微信排版.html" --title "文章标题"
Optional parameters:
--cover "/path/to/custom_cover.png": manually specify the cover (if not provided, automatically extract the first image from the body);--author "作者名": set the author displayed on the WeChat Official Account;--digest "摘要": customize the article ending or push summary (by default, extract from the body/title).
Cover image extraction rules (First-Image-as-Cover)
- First priority (explicit specification): when
--cover <图片路径>is passed on the command line, use that cover first; - Second priority (automatic extraction of the first image in the body): scan the first image in the article (supports Markdown local relative paths, absolute paths, network URL image downloads, Base64 images), upload it to the WeChat permanent material library to obtain
thumb_media_id; - Third priority (fallback cover generation): if the entire article has no illustrations, the system will automatically use headless Chrome to render a 900×383 artistic gradient large-title cover image as a fallback upload.
WeChat Official Platform credential configuration guide
Official API credential acquisition path (WeChat Developer Platform):
- Log in to the WeChat Developer Platform: Visit https://developers.weixin.qq.com/ and scan the QR code to log in;
- Locate your Official Account: At the bottom of the homepage, find "My Business", and click the Official Account you manage in the list;
- Obtain the development key: Enter the Official Account management page, and under the "Basic Capabilities" section, find "Development Key", obtain your
AppIDand generate and saveAppSecret; - Configure the IP whitelist (required): In the same area, find "IP Whitelist", and add this machine's public IP to the whitelist (run
curl cip.ccin the terminal to check the public IP); - Local configuration file: In the skill root directory's
wechat_config.json, fill in:
It can also be provided through system environment variables:{ "app_id": "你的微信公众号AppID", "app_secret": "你的微信公众号AppSecret" }WECHAT_APPIDandWECHAT_APPSECRET。
Notes: The WeChat Official Account Platform API requires the caller's outbound public IP to be in the whitelist. If you encounter
40164error during push, please add the IP address indicated in the error message to the Developer Platform [Basic Capabilities ➔ Development Key ➔ IP Whitelist]. See references/wechat_setup_guide.md。