SuperAPI AI Directory

wechat-article-formatter

Writing & research

View repository

Updated 10-15 20:07

About this skill

WeChat Official Account Article Formatting Tool (Claude Execution Guide)

Goal: Convert Markdown articles into beautiful HTML suitable for WeChat Official Accounts, enabling one-click publishing.

Core Value: 15x efficiency improvement (30 minutes → 2 minutes), consistent and professional formatting.


⚡ Execution Flow (Strictly Follow)

Step 1: Obtain the Input File

Scenario Determination:

Scenario How to Handle
User provides a file path Use that path directly
User pastes Markdown content First use the Write tool to save it as a .md file
Just used wechat-tech-writer Automatically find the most recently generated .md file (see integration guidance)
User only says "beautify the article" Ask the user: file path or paste content

Automatically Detect the Latest Article(Integration with wechat-tech-writer):

# 查找当前目录最新的 .md 文件
latest_md=$(ls -t *.md 2>/dev/null | head -1)
if [ -n "$latest_md" ]; then
    echo "检测到最新文章:$latest_md"
fi

Step 2: Check the examples Directory (Prefer Using Beautiful Templates)

⚠️ Important Rules:

  1. Prefer using the beautiful templates in examples, rather than the basic CSS themes
  2. Do not render the H1 title: WeChat Official Accounts have a separate title input box, and the HTML should not include the article title

Check Command:

cd /root/.claude/skills/wechat-article-formatter
ls -lh examples/

Available Templates:

Template File Style Features Applicable Scenarios
VSCode Blue Tech Style.html Intro block, numbered section titles, feature cards, operation steps Technical articles, product introductions, tutorials
Red vs Blue Showdown · In-Depth Review Template.html Gradient titles, comparison cards, data tables, quoted key lines Comparative reviews, in-depth analysis
Geek Dark Style.html Dark background, geek style In-depth technical articles, hacker style
Modern Minimalist Style.html Simple and clean General articles, concise style

Selection Logic:

文章分析:
├─ 技术/产品介绍类 → VSCode 蓝色科技风 ✅
├─ 对比/评测类 → 红蓝对决模板 ✅
├─ 深度技术文章 → 极客暗黑风
└─ 通用内容 → 现代极简风

Execution Method:

  1. Read the selected template file
  2. Refer to the template's component structure (intro block, cards, step lists, etc.)
  3. Skip the H1 title in Markdown(# title), start from the first paragraph or H2 (## section)
  4. Manually map the Markdown content into the template components
  5. Add a comment at the beginning of the HTML:<!-- ⚠️ 标题请在微信公众号编辑器中单独填写 -->
  6. ⚠️ Key Step: Convert Code Block Format
    • Use scripts/convert-code-blocks.py to convert the code blocks in the generated HTML into a WeChat-compatible format
    • Command:python scripts/convert-code-blocks.py input.html output.html
    • This will convert <pre><code> into <div> + <br> + &nbsp; format (the only code block format supported by WeChat)
  7. Generate a beautiful HTML file

If there is no suitable template, only then use the basic CSS theme conversion from Step 3.


Step 3: Choose a basic theme (only use when examples has no suitable template)

Decision tree(automatically choose OR ask the user):

文章内容分析:
├─ 包含代码块(```)或技术词汇多 → tech(科技风)
├─ 包含数据表格、商业术语 → business(商务风)
└─ 纯文字、通用内容 → minimal(简约风)

Theme comparison table:

Theme Applicable scenario Color scheme When to use
tech Technical articles, AI, programming tutorials Blue-purple gradient Default choice, from articles by wechat-tech-writer
minimal Life essays, reading notes Black, white, gray Text-only content, no code
business Business reports, data analysis Deep blue and gold Contains tables, data, charts

How to ask the user:

检测到文章包含代码块,建议使用 tech 主题。
需要切换主题吗?(tech / minimal / business)

Step 4: Execute conversion

Standard conversion command:

cd /root/.claude/skills/wechat-article-formatter

python scripts/markdown_to_html.py \
  --input "{文件路径}" \
  --theme {主题名} \
  --output "{输出路径}" \
  --preview

Parameter description:

  • --input: Markdown file path (required)
  • --theme: tech / minimal / business (default tech)
  • --output: HTML output path (optional, defaults to same-name .html)
  • --preview: Automatically open preview in browser after conversion (recommended)

Example:

# 最常用:使用 tech 主题转换并预览
python scripts/markdown_to_html.py \
  --input "Claude_Sonnet_4介绍.md" \
  --theme tech \
  --preview

Step 5: Quality check

After conversion is complete, you must check:

Use the Read tool to read the generated HTML file (first 50 lines), and check:

Check item How to verify Common issues
Heading styles View <h1>, <h2> tag's style attribute Styles lost → reconvert
Code highlighting View <pre><code> has a language identifier No highlighting → check whether the Markdown specifies a language
Image path View <img src=""> path Local path → remind the user it needs to be uploaded to WeChat
Table formatting View <table> has inline styles Confusing formatting → simplify the number of table columns

Quick check command:

# 查看 HTML 文件前 50 行
head -50 output.html

Step 6: Preview and feedback

Ask the user:

✅ 转换成功!已生成:{输出文件路径}

预览效果:
- 已在浏览器打开预览
- 或访问:file://{绝对路径}

请检查效果,满意吗?
- 满意 → 进入步骤6(发布指导)
- 需要调整 → 可以切换主题或手动修复

If the user is not satisfied:

Issue Solution
"I don't like the color" Switch theme and regenerate (tech/minimal/business)
"Code blocks are not highlighted" Check whether the Markdown code block specifies a language (```python)
"Images are not displaying correctly" Reminder: local images need to be uploaded to the WeChat editor
"The table is too wide" Suggest simplifying the table (≤4 columns) or accepting horizontal scrolling

Step 7: Publishing guidance

Complete guidance output to the user:

📋 发布到微信公众号步骤:

1. 打开微信公众号编辑器
2. ✅ 在标题栏填写文章标题:{从 Markdown 提取的标题}
3. 打开生成的 HTML 文件:{文件路径}
4. 在浏览器中按 Ctrl+A(全选)→ Ctrl+C(复制)
5. 粘贴到编辑器正文区(Ctrl+V)
6. 处理图片:
   - 删除无法显示的本地图片引用
   - 重新上传图片到微信编辑器
6. 最后检查:标题层级、段落间距、代码块
7. 使用微信编辑器的"预览"功能在手机查看
8. 确认无误后发布

⚠️ 注意事项:
- 样式已内联,可直接粘贴
- 本地图片需重新上传
- 粘贴后微信编辑器可能微调部分样式(正常)

详细发布指南:references/publishing-guide.md

🔄 Integration with wechat-tech-writer

Scenario: just used wechat-tech-writer to generate an article

Identification markers:

  • The user just said "write an article about XXX"
  • There is a newly generated .md file in the current directory

Automated workflow:

# 1. 查找最新文章
latest_article=$(ls -t *.md 2>/dev/null | head -1)

# 2. 确认是否是目标文章
echo "检测到最新文章:$latest_article"
echo "是否要转换这篇文章?(y/n)"

# 3. 自动选择 tech 主题(wechat-tech-writer 主要生成技术文章)
python scripts/markdown_to_html.py \
  --input "$latest_article" \
  --theme tech \
  --preview

Seamless transition wording:

检测到你刚用 wechat-tech-writer 生成了文章:{文件名}
现在为你美化格式,使用 tech 主题...

❌ Error handling table

Error message Cause What Claude should do
FileNotFoundError: Input file not found Incorrect file path Ask the user for the correct file path
Unknown theme: xxx Incorrect theme name Suggest available themes: tech/minimal/business
Theme CSS file not found Theme file missing Retry using the default tech theme
Conversion succeeds but code has no highlighting Markdown does not specify a language Remind the user to modify the code block (```python)
Images cannot be displayed Local path or external link is invalid Remind the user to re-upload in the WeChat editor
Table formatting is messy Table is too wide Suggest simplifying the table or converting it to an image

📚 Quick Reference

The 3 most commonly used commands

1. Standard conversion(most commonly used):

python scripts/markdown_to_html.py --input article.md --theme tech --preview

2. Batch conversion(multiple articles):

python scripts/batch_convert.py --input articles/ --theme minimal --workers 8

3. Live preview(write and view at the same time):

python scripts/preview_generator.py --input article.md --theme business

Quick answers to common questions

Q: Styles are lost after pasting into WeChat? A: Use "Paste" instead of "Paste and Match Style", or clear the editor and paste again.

Q: Code blocks are not highlighted? A: Make sure a language is specified in the Markdown:```python(不是 ```)

Q: How do I customize theme colors? A: Copy templates/tech-theme.css → modify the color variables → use --theme my-theme


📖 Complete Documentation Navigation

This document (SKILL.md): Claude execution guide (condensed version)

Other documents(user manual):

  • QUICKSTART.md - 3-minute quick start (new)
  • README.md - Complete feature introduction and parameter descriptions
  • EXAMPLES.md - 3 detailed usage examples
  • references/publishing-guide.md - Detailed publishing steps
  • references/theme-customization.md - Theme customization guide
  • references/wechat-constraints.md - WeChat platform limitations

How to use the documentation:

  • Claude mainly reads SKILL.md(this document) and QUICKSTART.md
  • Look at the references/ directory when detailed information is needed
  • Users mainly read README.md and EXAMPLES.md

✅ Execution Checklist (confirm after each execution)

  • Input file obtained (path or content)
  • Appropriate theme selected (automatically determined or user asked)
  • Conversion command executed
  • Generated HTML file checked (title, code, images)
  • User asked whether they are satisfied with the preview
  • Complete publishing guidance provided
  • Possible errors handled

Remember: The core of this skill isautomation + specialization, letting users complete in 2 minutes work that originally took 30 minutes!