SKILL.md
WX Article Creator
Use this skill when the user asks to draft or create a Weixin official account article (plain text or Markdown) and submit it as a draft.
Inputs
draft: User-provided draft text (plain or Markdown)title: Article titlethumbmediaid: Weixin thumbnail media id for draft (optional, see Workflow)thumbimage: Path to thumbnail image file (optional, used if thumbmedia_id not provided)format: Optional enum (auto,markdown,plain)
Outputs
markdown: Final markdown sourcehtml: Rendered HTMLwxcli_result: Command output
Rules
- Do not invent wxcli commands; use README-documented format.
- Always ask for user confirmation before running
wxcli. - Render HTML using exactly:
npx markdown-to-html-cli --source <SOURCE.md> --style=./style.css
- CSS must be loaded from
skills/wxarticle_creator/style.css. - Preserve meaning; no new facts. Keep length within +/-10% when polishing.
Workflow
- Detect input format.
- If format=auto, detect Markdown by headings (#), lists (-/1.), links, or code fences. - If Markdown is provided, keep it. - If plain text, convert it to Markdown with clear hierarchy.
- Convert plain text to structured Markdown (if needed).
- Use the provided title as an H1. - Derive H2 sections from topic shifts or leading phrases. - Use H3 for subtopics, and bullet/numbered lists for enumerations. - Keep original ordering and meaning.
- Polish Markdown lightly.
- Fix typos and improve readability. - Keep structure; do not add new facts.
- Handle thumbnail (thumbmediaid):
- If thumbmediaid is provided: Use it directly. - If thumbimage is provided (path to image file): - Upload the image: wxcli material upload --type image --file "<thumbimage>" - Extract the returned mediaid from the output. - If neither is provided: - Get the latest image from materials: wxcli material list --type image --offset 0 --count 1 --json - Extract the mediaid from the first item. - If no images exist, inform the user and proceed without thumbmediaid.
- Write Markdown source to a temporary file in a temp directory.
- Create a temp directory (e.g., /tmp/wxarticlecreator-<YYYYMMDD-HHMMSS>). - Save as <TMPDIR>/article-<YYYYMMDD-HHMMSS>.md (or another <SOURCE.md>). - Remove the temp directory after HTML is generated, unless the user requests it.
- Convert Markdown to HTML with the CLI.
- Copy skills/wxarticle_creator/style.css into the temp directory as style.css. - Run the command from the temp directory so ./style.css resolves. - Command: npx markdown-to-html-cli --source <SOURCE.md> --style=./style.css - Capture stdout as HTML output. - Ensure the content is wrapped in <div id="nice">...</div> if it is not already, so the stylesheet applies.
- User confirmation.
- Show polished markdown and a rendered HTML snippet. - If thumbmediaid was auto-fetched, mention which image is being used. - Ask: "Proceed to create Weixin draft with wxcli?"
- Submit via wxcli.
- Include --thumb-media-id <thumbmediaid> only if available. - Direct content: wxcli draft add --title "<title>" --content "<html>" --thumb-media-id <thumbmediaid> - From pipeline: npx markdown-to-html-cli --source <SOURCE.md> --style=./style.css | wxcli draft add --title "<title>" --content - --thumb-media-id <thumbmediaid> - Return output to the user.
Failure Handling
- If thumbnail upload fails, show the error and ask to retry or proceed without thumbnail.
- If getting latest image fails, inform the user and proceed without thumbmediaid.
- If the CLI conversion fails, show the error and ask to retry.
- If
wxclifails, show the error output and ask whether to retry or adjust inputs.