微算力 · API 导航与自营网关
API 接入 EN
未登录登录
✨

Xhs Md2img

Xhs Md2img · v0.1.0
安全 unknown 级 作者 zhang122994917 公开目录收录
1.1k 下载 2 安装 2.5k 收藏 1 浏览

简介

Xhs Md2img

原始描述

Convert Markdown text to beautiful Xiaohongshu (XHS) style card images with 5 themes, deterministic browser screenshot rules, auto-pagination, smart title ex...

通过你的 Agent 添加

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/xhs-md2img/
Codex CLI~/.codex/skills/xhs-md2img/
DeepSeek Harness~/.agents/skills/xhs-md2img/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

技能正文


name: xhs-md2img description: Convert Markdown text to beautiful Xiaohongshu (XHS) style card images with 5 themes, auto-pagination, smart title extraction, and AI-generated decorative backgrounds. version: 1.0.0 metadata: clawdbot: emoji: "🎴" requires: env: [DASHSCOPE_API_KEY] anyBins: [python3, python] primaryEnv: DASHSCOPE_API_KEY permissions: network: true filesystem: true

xhs-md2img

Convert Markdown text into beautiful Xiaohongshu (XHS) style card images. Supports 5 color themes, automatic pagination, smart LLM-powered title extraction, and AI-generated decorative backgrounds.

Overview

This skill renders Markdown content as multi-page card images optimized for Xiaohongshu (Little Red Book) posts. It handles the full pipeline from raw text to publish-ready PNG images.

Use cases:

  • Convert long-form content into XHS-ready multi-image posts
  • Generate styled card images from Markdown articles
  • Create visually appealing social media graphics with AI backgrounds

Quick Start

Minimal input — just provide Markdown text:

{
  "markdown": "## 5个提升效率的方法\n\n**1. 番茄工作法** — 25分钟专注 + 5分钟休息\n\n**2. 任务批处理** — 把相似的事情集中做\n\n> 效率不是做更多的事,而是用更少的时间做对的事。"
}

This produces a single card image with the default (white) theme.

Input Parameters

See templates/input-schema.json for the full JSON Schema. Key parameters:

Parameter Type Default Description
markdown string (required) Markdown content. Use --- for manual page breaks.
title string (auto-extracted) Cover title. If omitted, LLM extracts one from content.
author string — Author name shown on cover.
description string — Cover subtitle/description.
theme enum "default" Color theme: default, monokai, nord, sakura, mint.
font_family enum "sans-serif" Font: sans-serif, serif, wenkai.
padding enum "medium" Card padding: small, medium, large.
show_cover boolean true Whether to show cover block.
bg_style enum "ai_art" Background: ai_art (AI-generated) or none (solid color).

Rendering Pipeline

The rendering pipeline has 5 stages:

1. Smart Format (LLM)

If the input is plain text (not already Markdown), the LLM reformats it:

  • Title extraction: Extracts a short, punchy cover title (10-20 chars)
  • Body formatting: Adds Markdown structure (## headings, **bold**, - lists, > quotes)
  • Constraint: The LLM is strictly forbidden from modifying any original text content — it can only add Markdown formatting marks

The LLM prompt enforces: all emojis, hashtags, special symbols, and wording must be preserved verbatim. Only Markdown formatting (##, **, -, >, blank lines) may be added.

2. Markdown to HTML

Uses python-markdown with extensions:

  • tables, fenced_code, codehilite (Pygments), nl2br, sane_lists, smarty, attr_list, md_in_html, toc
  • XHS hashtags (#tag#) are converted to styled pill badges

3. HTML/CSS Card Construction

Builds a full HTML page with CSS styling per theme. Each card is a fixed-size div (375x500px base, exported at 3x = 1125x1500px). See templates/card-template.html for the template structure.

Card structure:

.xhs-card (fixed size, background color)
├── .bg-art (optional AI background, low opacity overlay)
└── .card-inner (z-index:1, above background)
    ├── .cover-block (title, author, description — first page only)
    └── .prose-content (rendered Markdown HTML)

4. Auto-Pagination (Playwright JS)

Content that overflows a single card is automatically split across multiple pages:

  1. Playwright measures each top-level element's height in the browser
  2. Elements are grouped into pages that fit the card height
  3. New card divs are created in the DOM with cloned background art
  4. Page numbers (1 / N) are added to each card
  5. The last card is shrunk to fit its content (avoids large empty space)

5. Screenshot & Upload

Each .xhs-card div is screenshotted as PNG via Playwright. Images are uploaded to Alibaba Cloud OSS if configured, otherwise returned as base64 data URIs.

Theme System

5 built-in themes with carefully tuned palettes. See references/themes.md for full hex values.

Theme Background Feel
default White #ffffff Clean, professional
monokai Dark #272822 Tech, developer-oriented
nord Deep blue #2e3440 Nordic minimalist
sakura Soft pink #fff5f5 Warm, feminine
mint Light green #f0faf4 Fresh, natural

AI Background Generation

When bg_style: "ai_art", the skill generates a subtle decorative background image:

  1. Prompt generation: LLM creates an image prompt based on the card's text content and theme
  2. Image generation: Routes to one of two providers automatically:
    • Gemini (if LLM_API_KEY points to googleapis.com): Native Gemini API, returns base64 data URI, synchronous
    • DashScope wanx (if DASHSCOPE_API_KEY is set): Async submit + poll, returns URL
  3. Compositing: Background is overlaid at very low opacity (8-18% depending on theme) behind the card content

See references/api-reference.md for API details.

Prompt constraints: Generated backgrounds are always abstract decorative elements (watercolor, bokeh, geometric lines, plant silhouettes) — never text, faces, or specific objects.

Output Format

{
  "__type": "xhs_card_images",
  "title": "Extracted or provided title",
  "theme": "default",
  "total_pages": 3,
  "pages": [
    {
      "index": 0,
      "page": 1,
      "total_pages": 3,
      "width": 1125,
      "height": 1500,
      "size_bytes": 123456,
      "url": "https://...",
      "oss_uploaded": true
    }
  ]
}

If OSS is not configured, each page includes data_uri instead of url, with oss_uploaded: false.

Privacy & External Endpoints

This skill makes network calls to:

Endpoint Purpose Data sent
LLM API (configurable) Smart formatting, BG prompt generation Text content (title + body summary)
DashScope wanx API AI background image generation English image prompt (no user content)
Gemini API AI background image generation (alternative) English image prompt (no user content)
Alibaba Cloud OSS Image upload (optional) Generated PNG images

No user content is sent to image generation APIs — only LLM-generated English art prompts describing abstract decorative elements.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

没有标签

同类 Skill