Wechat Article Formatter 标志

Wechat Article Formatter

社区
iamzifei
wechat-article-formatter

Format markdown and publish to WeChat Official Account via bm.md rendering + WeChat official API 新手引导:输入 `/公众号排版 新手`、「这个怎么用」「第一次用」「能干嘛」时,走 SKILL.md 的〈新手上路〉,不要直接开始干活。

Add to TypingMind

概览

发布者iamzifei
代码仓库wechat-article-formatter-skill
技能名称wechat-article-formatter
星标数
77
复刻数
11
附带文件
2
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 2 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 iamzifei 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Wechat Article Formatter AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/iamzifei/wechat-article-formatter-skill/tree/main
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/iamzifei/wechat-article-formatter-skill.git \
  .claude/skills/wechat-article-formatter
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Wechat Article Formatter,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Wechat Article Formatter。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Wechat Article Formatter 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

WeChat Article Formatter & Publisher

Format markdown articles with bm.md styling and publish directly to WeChat Official Account drafts via the official API.

Overview

  1. Read markdown file (typically wechat.md from article directory)
  2. Upload local images to WeChat CDN via media/uploadimg API
  3. Replace local image paths with WeChat CDN URLs in markdown
  4. Render markdown to styled HTML via bm.md API with custom CSS
  5. Publish to WeChat draft via official draft/add API

CRITICAL: Do NOT use third-party publishing APIs (e.g. 微绿 wechat-publish). They strip inline CSS styles. Always use WeChat's official draft/add API directly.

Credentials

Read from ~/.env:

VariablePurpose
WECHAT_APP_IDWeChat Official Account AppID
WECHAT_APP_SECRETWeChat Official Account AppSecret

If not found, prompt the user to provide them and save to ~/.env.

Workflow

Step 1: Identify Input

The user provides a markdown file path (e.g. wechat.md in an article directory).

Detect the article directory to find:

  • promotion.md → extract digest/summary
  • _attachments/ → local images
  • Brand config from the conversation context → author name

Step 2: Get WeChat Access Token

python
params = urlencode({
    'grant_type': 'client_credential',
    'appid': WECHAT_APP_ID,
    'secret': WECHAT_APP_SECRET
})
# GET https://api.weixin.qq.com/cgi-bin/token?{params}

If error 40164 (IP not in whitelist), instruct user to add the IP at: mp.weixin.qq.com → 设置与开发 → 基本配置 → IP白名单.

Step 3: Upload Images to WeChat CDN

CRITICAL: Upload ALL images in the SAME session. WeChat CDN URLs from previous sessions may expire.

Use media/uploadimg API for inline content images:

python
# POST https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token={token}
# Content-Type: multipart/form-data
# Body: media=@image_file
# Response: {"url": "http://mmbiz.qpic.cn/..."}

Use material/add_material API for cover/thumb image:

python
# POST https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={token}&type=image
# Content-Type: multipart/form-data
# Body: media=@cover_image
# Response: {"media_id": "...", "url": "..."}

For remote images (e.g. https://i.ibb.co/...), download first, then upload to WeChat CDN.

After uploading, replace all local/remote image paths in the markdown with WeChat CDN URLs before rendering.

Step 4: Render with bm.md

Read custom CSS from {{SKILL_DIR}}/styles/custom.css.

IMPORTANT: Write the JSON payload to a temp file and use curl -d @file to avoid shell escaping issues.

python
payload = json.dumps({
    "markdown": md_content,
    "markdownStyle": "green-simple",
    "codeTheme": "kimbie-light",
    "customCss": css_content,
    "enableFootnoteLinks": True,
    "openLinksInNewWindow": True,
    "platform": "wechat"
}, ensure_ascii=False)

# Write to /tmp/bm-payload.json, then:
# curl -s -X POST https://bm.md/api/markdown/render \
#   -H "Content-Type: application/json" \
#   -d @/tmp/bm-payload.json

The ensure_ascii=False is critical — without it, Chinese characters become \uXXXX escape sequences.

Step 5: Publish to WeChat Draft

python
draft_payload = json.dumps({
    "articles": [{
        "title": title,
        "author": author,                    # e.g. "在悉尼和稀泥"
        "thumb_media_id": thumb_media_id,     # from Step 3 material upload
        "content": html,                      # from Step 4 bm.md render
        "digest": digest,                     # from promotion.md, max ~60 Chinese chars
        "need_open_comment": 1,               # enable comments
        "only_fans_can_comment": 0,           # allow all users to comment
        "original_article_type": 1,           # declare as original content
        "reward_wording": "喜欢这篇文章,请我喝杯咖啡",  # enable tipping
        "creation_source_type": 1             # 个人观点,仅供参考
    }]
}, ensure_ascii=False).encode('utf-8')

# POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token={token}

Default publish settings:

FieldValueDescription
need_open_comment1Enable comments
only_fans_can_comment0All users can comment
original_article_type1Declare as original
reward_wording"喜欢这篇文章,请我喝杯咖啡"Enable tipping
creation_source_type1个人观点,仅供参考

Digest extraction from promotion.md:

Look for ## 文章摘要 section, extract text, truncate to ~60 Chinese characters (WeChat limit is 120 bytes).

Author resolution (first match wins):

  1. User explicitly specified
  2. Brand config author field
  3. Brand config 品牌名称 field

Step 6: Report Result

WeChat Publishing Complete!

Title: {title}
Author: {author}
Digest: {digest}
Original: ✓ declared
Tipping: ✓ enabled
Comments: ✓ open to all
Images: {N} uploaded to WeChat CDN
media_id: {media_id}

→ Preview at: https://mp.weixin.qq.com (内容管理 → 草稿箱)

Markdown Content Order for WeChat

When building the WeChat markdown, elements should appear in this order:

1. 关注引导文字 (e.g. 👆 「关注」加「星标」...)
2. 封面图 (cover image)
3. --- 分隔线
4. 正文内容 (article body with inline images)
5. --- 分隔线
6. 作者介绍 (about author section)
7. --- 分隔线
8. 推广区块 (promo blockquote with image)
9. --- 分隔线
10. 互动引导 (engagement CTA)

The H1 title should be REMOVED from markdown — WeChat displays its own title from the title field.

Common Pitfalls

PitfallSolution
Chinese shows as \uXXXXUse ensure_ascii=False in ALL json.dumps() calls
Images not displayingUpload in same session; don't reuse old CDN URLs
Styles stripped (plain text)Use WeChat official draft/add API, NOT third-party APIs
40164 IP whitelist errorAdd current IP at mp.weixin.qq.com → 基本配置 → IP白名单
45004 digest too longKeep digest under 60 Chinese characters
40007 invalid media_idUpload cover via material/add_material first to get thumb_media_id
> [!NOTE] renders wrongConvert GitHub alerts to regular > blockquotes for WeChat

bm.md API Reference

Render: POST https://bm.md/api/markdown/render

ParameterTypeDefaultDescription
markdownstringrequiredMarkdown content
markdownStylestringayu-lightStyle ID (use green-simple)
codeThemestringkimbie-lightCode highlight theme
customCssstring""Custom CSS scoped to #bm-md
enableFootnoteLinksbooleantrueConvert links to footnotes
openLinksInNewWindowbooleantrueLinks open in new window
platformstringhtmlTarget: html, wechat, zhihu, juejin

Available styles: ayu-light, bauhaus, blueprint, botanical, green-simple, maximalism, neo-brutalism, newsprint, organic, playful-geometric, professional, retro, sketch, terminal

Styling Features

The custom CSS (styles/custom.css) provides:

  • Optima/Microsoft YaHei fonts
  • Green accent color (rgb(53, 179, 120))
  • H2 headings: white text on black background
  • Bold text: green color
  • Blockquotes: green left border
  • Responsive tables with alternating row colors
  • Code blocks with dark background

Dependencies

  • WeChat Official Account API credentials (~/.env)
  • bm.md rendering service (no auth required)
  • Custom CSS at {{SKILL_DIR}}/styles/custom.css

新手上路(用户不知道该输入什么时,走这里)

触发:/公众号排版 新手、「这个怎么用」「第一次用」「能干嘛」「带我走一遍」, 以及用户输入了技能名却没有给任何任务的时候。

这个模式的铁律:不假设、不索取。用户可能什么都没准备, 不要一上来就问他要文件、要 API key、要具体需求。按下面四步走:

一、先说清楚这是什么(三句话以内)

一句话:把 Markdown 排成公众号能直接用的样式。 公众号编辑器不认 Markdown,手动调格式很费时间, 这个技能把排版做完,还能换主题。

二、给编号选项,让他按回车就能继续

不要问开放式问题(「你想做什么?」对新手是负担)。给 3 个选项加一个默认:

想先看哪个?(直接回车 = 1)
  1. 先看看排出来长什么样(示例)
  2. 排我的这篇 Markdown
  3. 有哪些主题可以选

三、直接演示一遍,边做边解释

选完立刻做给他看,用示例数据,不需要他提供任何东西。 每做完一步,加一行「💡 刚才发生了什么」,一句话说明这步的意义。

四、毕业

演示完只问一个是非题:「要不要用你自己的文章真跑一遍?」 答是就进正常流程;答否就告诉他随时回来输 /公众号排版 新手。

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Wechat Article Formatter AI 技能有什么作用?

Format markdown and publish to WeChat Official Account via bm.md rendering + WeChat official API 新手引导:输入 `/公众号排版 新手`、「这个怎么用」「第一次用」「能干嘛」时,走 SKILL.md 的〈新手上路〉,不要直接开始干活。

为什么在 TypingMind 中使用 Wechat Article Formatter?

因为您只需安装一次,就能搭配任何模型使用。Wechat Article Formatter 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Wechat Article Formatter?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/iamzifei/wechat-article-formatter-skill/tree/main。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Wechat Article Formatter?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Wechat Article Formatter 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Wechat Article Formatter 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Wechat Article Formatter AI 技能免费吗?

iamzifei 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇