Coding

HTML to WeChat

Try it

Take existing HTML content (file, URL, or pasted HTML) and publish it directly to WeChat Official Account draft box. No file conversion, no web scraping — ju...

What it does

Take **existing HTML content** — a file, a URL, or pasted HTML — and publish it to the **WeChat Official Account draft box** in one streamlined workflow.

The skill document

HTML to WeChat

Take existing HTML content — a file, a URL, or pasted HTML — and publish it to the WeChat Official Account draft box in one streamlined workflow.

This is the simplest WeChat publishing skill: no file conversion, no web scraping. Just HTML, a compatibility check, and publish.

User-Facing Promise

Accept requests like:

  • "把这个 HTML 文件发到我的微信公众号"
  • "我有一个现成的 HTML 页面,帮我发到公众号草稿箱"
  • "Publish this HTML to my WeChat account"
  • "把这个链接里的 HTML 推送到微信"
  • "我有一段 HTML 代码,发到公众号"
  • "Help me push this HTML page to my WeChat draft box"

Return a published draft in the WeChat draft box, not a proposal.


First-Time Setup

1. Configure WeChat Credentials

You need a WeChat Official Account (服务号 or 订阅号 with API access).

Get your credentials:

  1. Log in to https://mp.weixin.qq.com/
  2. Go to: 设置与开发 -> 基本配置
  3. Copy your AppID and reset/view AppSecret
  4. Add your server's public IP to the IP白名单

SECURITY: NEVER hardcode credentials in scripts or source files. Always use environment variables or interactive prompts.

Set environment variables (recommended):

On macOS / Linux:

export WECHAT_APP_ID="your_appid_here"
export WECHAT_APP_SECRET="your_appsecret_here"

On Windows (PowerShell, persistent):

[Environment]::SetEnvironmentVariable("WECHAT_APP_ID", "your_appid_here", "User")
[Environment]::SetEnvironmentVariable("WECHAT_APP_SECRET", "your_appsecret_here", "User")

On Windows (Command Prompt, session only):

set WECHAT_APP_ID=your_appid_here
set WECHAT_APP_SECRET=your_appsecret_here

No environment variables set? The publish script will prompt interactively on first run. You can also pass credentials at runtime via Python subprocess (see Phase 5).

2. Install Companion Skill

This skill depends on the anything-to-wechat skill from ClawHub:

clawhub install anything-to-wechat
  • anything-to-wechat -- provides publish_to_wechat.py (WeChat API publishing) and convert_for_wechat.py (HTML compatibility conversion)

Prerequisites

DependencyRequiredPurpose
beautifulsoup4 (pip)YesHTML parsing for validation and conversion
cssutils (pip)YesCSS parsing for style inlining
Pillow (pip)YesCover image compression
requests (pip)YesWeChat API HTTP calls
anything-to-wechat skillYespublish_to_wechat.py and convert_for_wechat.py

All pip dependencies auto-install on first use if missing.


Workflow

Phase 1: Collect HTML Input

Determine the source of the HTML content.

If the user has already provided one of the following, skip to Phase 2:

  • A local file path (e.g., ./article.html)
  • A URL pointing to an HTML page
  • Pasted HTML source code

Otherwise, ask the user:

Question: "请提供你想发布到微信公众号的 HTML 内容"
Options:
  - "本地 HTML 文件路径"
  - "粘贴 URL 链接"
  - "直接粘贴 HTML 代码"

Handling each input type:

Input TypeAction
Local file pathRead the file directly. Use the Read tool or open in Python.
URLUse the WebFetch tool to retrieve the page HTML source.
Pasted HTMLSave the pasted content to a temporary file (e.g., /input.html).

Important for URLs: Use WebFetch only to fetch the raw HTML. If the page requires JavaScript rendering or returns a login wall, inform the user and ask them to provide the HTML file directly.

Save the HTML to /input.html before proceeding.


Phase 2: Validate HTML for WeChat Compatibility

Before converting, inspect the HTML for known WeChat incompatibilities.

Read the HTML file and check for the following issues:

WeChat Strips / Rejects

IssueDetection MethodSeverity
`` tagsSearch for `` stylesheet tagsSearch for `` tags

Decision after validation:

  • No issues found -- Skip Phase 3, proceed directly to Phase 4.
  • Issues found -- Proceed to Phase 3 for automated conversion.

Report the validation results to the user with a brief summary:

[WeChat Compatibility Check]
- Found 2  tags (will be inlined)
- Found CSS variables (will be resolved)
- Found position:sticky (will be removed)
- File size: 145KB (OK, under 2MB limit)
- Background: #ffffff (OK)

Phase 3: Convert HTML for WeChat

If Phase 2 found incompatibilities, run the conversion script from the anything-to-wechat skill:

python "/scripts/convert_for_wechat.py" \
  --input "/input.html" \
  --output "/wechat_article.html"

This script automatically:

  • Extracts CSS from `` tags and inlines them as style="" attributes
  • Converts dark backgrounds to light themes
  • Resolves all CSS variables (var(--xxx)) to literal color values
  • Removes WeChat-incompatible CSS properties (position: fixed/sticky, backdrop-filter, z-index)
  • Ensures all elements have inline styles
  • Applies system font fallbacks

After conversion: Re-validate the output by reading wechat_article.html and confirming:

  1. No `` tags remain
  2. No `` tags remain
  3. All elements have inline style="" attributes
  4. Background is light (white or near-white)
  5. File size is under 2MB

If any issues persist after conversion, manually fix them using the Edit tool:

  • Remove remaining or blocks
  • Replace dark background colors with #ffffff
  • Add max-width: 680px; margin: 0 auto; to the outermost container
  • Ensure font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif on the body

If no conversion was needed in Phase 2, copy the input file:

copy "/input.html" "/wechat_article.html"

Phase 4: Prepare Cover Image

WeChat requires a cover image for thumb_media_id upload. The image must be under 64KB.

Option A: User provides a cover image

If the user supplied a cover image path, use it directly and proceed to compression.

Option B: Generate a cover image

Use the ImageGen tool with a prompt derived from the HTML content:

  • Read the HTML or first to determine the topic
  • Generate a visually compelling cover image
  • Size: 1024x768 (WeChat cover ratio 4:3)
  • Save as /wechat_cover.png

Compress the cover image:

WeChat requires cover images (thumb_media_id) to be under 64KB.

python "/scripts/compress_image.py" \
  --input "/wechat_cover.png" \
  --output "/wechat_cover_compressed.jpg" \
  --max-size 64

Always run compression, even if the image seems small -- it will not enlarge files.

Fallback: If compress_image.py fails to reach 64KB, use ImageGen to regenerate a simpler cover image (fewer details, simpler composition, larger flat color areas) and try compression again.


Phase 5: Publish to WeChat Draft Box

Use publish_to_wechat.py from the anything-to-wechat skill.

IMPORTANT: Credentials must NEVER be hardcoded in scripts. Use environment variables or the Python subprocess pattern below.

macOS / Linux

WECHAT_APP_ID="$WECHAT_APP_ID" WECHAT_APP_SECRET="$WECHAT_APP_SECRET" \
python "/scripts/publish_to_wechat.py" \
  --file "/wechat_article.html" \
  --title "" \
  --cover "/wechat_cover_compressed.jpg" \
  --digest ""

Windows (Python subprocess for env vars + UTF-8 encoding)

On Windows, environment variable passing via set in cmd or $env: in PowerShell can be unreliable across sessions and may have encoding issues with Chinese characters. Use the Python subprocess pattern:

python -c "
import os, subprocess, sys
os.environ['WECHAT_APP_ID'] = ''
os.environ['WECHAT_APP_SECRET'] = ''
result = subprocess.run([
    sys.executable,
    r'\scripts\publish_to_wechat.py',
    '--file', r'\wechat_article.html',
    '--title', '',
    '--cover', r'\wechat_cover_compressed.jpg',
    '--digest', ''
], capture_output=True, text=True, encoding='utf-8')
print(result.stdout)
print(result.stderr)
"

Key Windows notes:

  • Always pass encoding='utf-8' to subprocess.run to handle Chinese titles and digests correctly
  • Use raw strings (r'...') for Windows file paths to avoid backslash escape issues
  • Never write credentials to disk -- pass them via os.environ in the subprocess wrapper only

If credentials are not set: The script will prompt interactively for AppID and AppSecret.

Handle IP whitelist errors:

If the API returns ip not in whitelist:

  1. Extract the server's public IP from the error message
  2. Tell the user: "请将 IP `` 添加到微信公众号后台的 IP 白名单中(设置与开发 -> 基本配置 -> IP白名单)"
  3. Wait for confirmation, then retry the publish command

Phase 6: Confirm and Handoff

After successful publishing, report to the user:

  1. Success status with the Media ID
  2. Link to WeChat backend: https://mp.weixin.qq.com/
  3. Message: "文章已发送到你的微信公众号草稿箱,请登录微信公众平台审核后一键发布。"

Include the following summary:

[Publish Complete]
- Title: 
- Media ID: 
- Cover image:  (KB)
- HTML file:  (KB)
- Digest: 
- Next step: Log in to https://mp.weixin.qq.com/ to review and publish

WeChat HTML Compatibility Reference

What WeChat Strips

StrippedEffect
`` tagsAll block-level CSS lost
``External stylesheets removed
CSS variables (var(--*))Rendered as empty / broken
position: fixed / stickyLayout elements may overlap or disappear
backdrop-filterVisual effect lost
z-indexElement layering ignored
@font-face / web fontsFalls back to system font
`` tagsAll JavaScript removed
`` tagsEmbedded content removed
External images (some)Must be uploaded to WeChat CDN

What WeChat Requires

RequirementDetail
Inline stylesAll styling via style="" attributes on elements
Light background#ffffff or near-white (WeChat renders on white)
Max-width 680pxOuter container width for article display
System fonts-apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif
Under 2MB totalCombined HTML size limit
`` tagsImages must use `` with inline width/height styles
Cover under 64KBFor thumb_media_id upload

  Article Title
  Article content...
  


Error Handling

ErrorCauseAction
`` tags remain after conversionConversion script missed nested stylesManually inline remaining styles with Edit tool
HTML file exceeds 2MBToo many inline assets or large contentSimplify content, reduce image count, split into parts
Cover image > 64KB after compressionImage too complex for JPEG compressionRegenerate simpler cover via ImageGen, retry compression
Cover image upload failsWeChat CDN rejectionRetry with different format (JPG instead of PNG) or smaller dimensions
invalid content from WeChat APIRemaining unsupported CSS or HTMLRe-run convert_for_wechat.py, manually inspect output
ip not in whitelistServer IP not in WeChat backend whitelistExtract IP from error, guide user to add it, retry
access_token expiredToken TTL exceeded (7200s)Re-fetch token and retry publish
No AppID / AppSecretCredentials not configuredScript prompts interactively, or ask user to set env vars
beautifulsoup4 not installedMissing pip dependencyAuto-installed by convert_for_wechat.py on first run
Chinese characters garbled (Windows)Console encoding not UTF-8Use encoding='utf-8' in Python subprocess pattern
File not foundIncorrect path or workspace issueVerify path exists before proceeding
URL returns 403 / login wallSite blocks automated fetchingAsk user to provide HTML file directly

Script Reference

ScriptLocationPurpose
compress_image.pyhtml-to-wechat/scripts/Compress images to meet WeChat 64KB cover limit
convert_for_wechat.pyanything-to-wechat/scripts/Convert HTML with style tags to inline-style WeChat HTML
publish_to_wechat.pyanything-to-wechat/scripts/Publish HTML to WeChat Official Account draft box

Configuration

VariableRequiredDescription
WECHAT_APP_IDYesWeChat Official Account AppID. Read from env var or prompted interactively.
WECHAT_APP_SECRETYesWeChat Official Account AppSecret. Read from env var or prompted interactively.

Never commit credentials to version control. Always use environment variables, and the publish script falls back to interactive prompts when env vars are missing.

Related skills

Generate and edit Draw.io, Mermaid, and Excalidraw diagrams from natural language using a structured JSON spec.

by nssa.io1.0k installs47 stars

Find why your productivity system keeps failing, then apply the smallest fix — capacity math, bottleneck routing, durable local notes.

by Iván855 installs69 stars

Join a video meeting as an AI bot with voice, avatar, and screenshare across four operating modes.

by johnpatternai22 installs8 stars

Stores durable facts in a categorized, plain-markdown vault on disk, alongside your agent's built-in memory.

by Iván559 installs18 stars

Fetch raw ad creative, app, ranking, and revenue data from AdMapix as structured JSON.

by fly0pants4.3k installs296 stars

More from lutongsuo

Browse all skills

将任意文件(PDF、Word、Excel、PPT、图片、音频、网页等)转换为 Markdown,再生成为精美的微信公众号文章并发布到草稿箱。组合 markitdown + md_to_wechat_html + publish_to_wechat 三阶段流水线。Use when the user wants to...

by lutongsuo1 installs

沃尔夫冈·赖因哈德《征服世界:一部欧洲扩张的全球史,1415~2015》结构化知识库技能。包含24章深度摘要、12个核心分析框架、48个专业术语、15个分析模式及决策速查表。当用户讨论欧洲扩张史、殖民主义、帝国主义、去殖民化、全球史、大航海时代、东印度公司、奴隶贸易、殖民遗产等话题时激活。适用于学术研究辅助、历史...

by lutongsuo

One-step workflow: accept any file (PDF, DOCX, CSV, Markdown), folder, URL, or idea → generate polished HTML via html-anything → auto-convert for WeChat comp...

by lutongsuo

抓取任意网页内容,AI 智能整理格式,自动生成封面图和配图,发布到微信公众号草稿箱。支持微信公众号文章、新闻网站、技术博客、知乎、CSDN 等。Use when the user wants to scrape a web page and publish it to WeChat.

by lutongsuo

Generate high-quality videos from text or images with support for text-to-video, image animation, multi-image transitions, and keyframe animations via asynch...

by lutongsuo1 installs

升级版图像生成模型,支持高信息密度复杂场景文生图与图生图,具备风格转换、多图合成及灵活尺寸输出能力。

by lutongsuo1 installs