Xhs Md2img
by @zhang122994917
Convert Markdown text to beautiful Xiaohongshu (XHS) style card images with 5 themes, deterministic browser screenshot rules, auto-pagination, smart title ex...
clawhub install xhs-md2picπ About This Skill
name: xhs-md2img description: Convert Markdown text to beautiful Xiaohongshu (XHS) style card images with 5 themes, deterministic browser screenshot rules, auto-pagination, smart title extraction, and AI-generated decorative backgrounds. 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 Xiaohongshu (XHS) style multi-page card images with deterministic browser rendering and screenshot behavior.
Overview
This skill renders Markdown content as publish-ready XHS card images and is designed to run reliably in browser screenshot services.
Use cases:
Quick Start
Minimal input β just provide Markdown text:
{
"markdown": "## 5δΈͺζεζηηζΉζ³\n\n1. ηͺθε·₯δ½ζ³ β 25ειδΈζ³¨ + 5ειδΌζ―\n\n2. δ»»ε‘ζΉε€η β ζηΈδΌΌηδΊζ
ιδΈε\n\n> ζηδΈζ―εζ΄ε€ηδΊοΌθζ―η¨ζ΄ε°ηζΆι΄εε―ΉηδΊγ"
}
Default export is one 1125x1500 PNG card (375x500 CSS px at export_scale=3).
Input Parameters
See templates/input-schema.json for the full schema.
Core content/style params:
markdown (required): Markdown content. Use --- for manual page breaks.title, author, description: Cover metadata.theme: default, monokai, nord, sakura, mint.font_family: sans-serif, serif, wenkai.padding: small, medium, large.show_cover: Whether to show cover block.bg_style: ai_art or none.Browser screenshot control params:
card_width / card_height: Single card CSS size (default 375x500).export_scale: Pixel ratio multiplier (default 3).viewport_width / viewport_height: Browser viewport size for rendering stability.page_gap: Vertical gap between cards in DOM (default 20).pagination_mode: mixed (default), auto, manual_only.max_pages: Hard limit to avoid runaway pagination.show_page_number: Whether to render 1 / N indicator.avoid_orphan_heading: Keep headings with at least one following block.last_page_compact: Shrink last card when content is short.Deterministic Browser Screenshot Contract
Use these hard rules for consistent XHS-like output:
1. Fixed card geometry
3:4 (375x500 base).card_width * export_scale by card_height * export_scale.export_scale=3 for XHS quality (1125x1500).2. Stable browser context
deviceScaleFactor=export_scale.440x760 for default card).3. Render readiness gates (must pass before pagination/screenshot)
document.fonts.ready.document.body[data-fonts-loaded="true"] is present..xhs-card bounding boxes.4. Element-only screenshot
.xhs-card element, never full page + crop.For implementation runbook and failure checks, read references/browser-screenshot-spec.md.
Rendering Pipeline
1. Smart Format (LLM)
If input is plain text, reformat to Markdown without changing wording:
##, **, lists, quotes)2. Markdown to HTML
Use python-markdown with extensions:
tables, fenced_code, codehilite, nl2br, sane_lists, smarty, attr_list, md_in_html, toc#tag#) into styled pills3. HTML/CSS Card Construction
Use templates/card-template.html with fixed card dimensions and theme variables.
Card layers:
.xhs-card: fixed-size card container.bg-art: optional low-opacity decorative image.card-inner: content layer above background4. Pagination Rules (Critical)
Apply pagination in DOM, not PDF/print pagination.
Priority order:
1. Split by manual separators (---) first.
2. Within each segment, split by top-level block elements.
3. If avoid_orphan_heading=true, never place a heading as the last visible block on a page.
4. Keep list/table/code blocks intact when possible.
5. If a single block exceeds one page, split safely:
liOverflow rule:
scrollHeight <= clientHeight.5. Multi-Page Screenshot Output
For each page:
.xhs-card nodepage / total_pagesOutput shape:
{
"__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, return data_uri for each page.
XHS Visual Quality Checklist
Before returning images, verify:
last_page_compact=trueTheme System
5 built-in themes are defined in references/themes.md.
| 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":
1. LLM generates an abstract decorative prompt from content/theme
2. Provider auto-select:
LLM_BASE_URL is GoogleConstraints:
See references/api-reference.md for provider API details.
Privacy & External Endpoints
Network calls may include:
No raw user document is sent to image models; only abstract prompt text is used.
π‘ Examples
Minimal input β just provide Markdown text:
{
"markdown": "## 5δΈͺζεζηηζΉζ³\n\n1. ηͺθε·₯δ½ζ³ β 25ειδΈζ³¨ + 5ειδΌζ―\n\n2. δ»»ε‘ζΉε€η β ζηΈδΌΌηδΊζ
ιδΈε\n\n> ζηδΈζ―εζ΄ε€ηδΊοΌθζ―η¨ζ΄ε°ηζΆι΄εε―ΉηδΊγ"
}
Default export is one 1125x1500 PNG card (375x500 CSS px at export_scale=3).