md-to-image (v0.2)
Render Markdown as a JPEG image and send it via openclaw message send --media.
将 Markdown 渲染为 JPEG 图片,通过 openclaw message send --media 发送。
适用于不原生支持 Markdown 的聊天渠道(如微信/WeChat)。
Trigger Conditions / 触发条件
Auto Trigger (Session Policy) / 自动触发(Session 策略)
当传入 --session <id> 且 CONFIG.md 存在时,满足以下任一条件即渲染图片:
When --session <id> is passed and CONFIG.md exists, auto-render if any of:
| Condition 条件 | Description 说明 |
|---|---|
| > 600 characters / >600 字 | Plain text character count 纯文字字符数 |
| Fenced code blocks / 围栏代码块 | Triple backtick `` ```lang ```` format |
| LaTeX formulas / LaTeX 公式 | $inline$ or $$display$$ |
| Mermaid diagrams / Mermaid 图表 | `` ```mermaid ```` |
| Markdown tables / Markdown 表格 | ≥2 rows 行(表头/分隔行/数据行均算) |
| > 20 lines / >20 行 | Any content 任意内容 |
Manual Trigger / 手动触发
Any session can manually request image rendering. 任意 session 均可手动触发:
- "做成图" / "做成图片"
- "md转图" / "md转图片"
- "render as image"
- "转成图片"
Do NOT Render / 不触发
| Condition 条件 | Description 说明 |
|---|---|
| < 300 chars, no special format / <300字,无特殊格式 | Short plain text answers 短回复 |
| Simple lists without formatting / 无格式简单列表 | Bullet points only 仅纯列表 |
| User says "直接发文字" / "plain text" | User preference override 用户偏好覆盖 |
Session Configuration / Session 配置
在 skill 目录下创建 CONFIG.md 来启用 per-session 自动策略:
Create CONFIG.md in the skill directory to enable per-session auto-policy:
# md-to-image Session Config / 会话配置
# List sessions that should use auto-render policy
# 列出需要自动渲染的 session
auto_sessions:
- "o9cq80zQWEnhk24254c6jR82dMXM@im.wechat"
# - "other-session-id@channel"
- Sessions not in the list only respond to manual triggers
- 不在列表中的 session 仅响应手动触发
- Session key format:
<chat_id>@<channel> - 如何获取:运行
/session查看你的 session key - 示例:
o9cq80zQWEnhk24254c6jR82dMXM@im.wechat
Usage / 使用方式
# Basic render / 基础渲染
bash render.sh input.md output.jpg
# With theme / 指定主题
bash render.sh --theme dark input.md output.jpg
# With page split / 自动分页
bash render.sh --pages a5 input.md output.jpg
# Combined / 组合使用
bash render.sh --theme nord --pages a4 input.md output.jpg
# With session auto-policy / 启用 session 策略
bash render.sh --session "xxx@im.wechat" input.md output.jpg
# Send via channel / 通过渠道发送
openclaw message send --channel <channel> --target "<id>" --media output.jpg
Options / 选项
| Option 选项 | Values 值 | Default 默认 | Description 说明 |
|---|---|---|---|
--theme |
light, dark, sepia, nord |
light |
Color theme 色彩主题 |
--pages |
none, a4, a5 |
none |
Page split mode 分页模式 |
--session |
<id> |
— | Enable session auto-policy 启用 session 策略 |
Theme Auto-Selection / 主题自动选择
Without --theme, auto-selects by local hour:
不指定 --theme 时,根据本地时间自动选择:
| Time 时段 | Theme 主题 |
|---|---|
| 06:00–17:59 | light |
| 18:00–05:59 | dark |
Setup / 安装
bash /path/to/skills/md-to-image/setup.sh
Dependencies / 依赖
| Item 组件 | Required 必需 | Notes 说明 |
|---|---|---|
| python3 | Yes 是 | Runtime 运行时 |
| playwright | Yes 是 | Primary renderer 主渲染引擎 (Chromium) |
| wkhtmltoimage | No 否 | Fallback renderer 备用渲染引擎 |
| python3-pillow | Yes 是 | Page split 分页处理 |
| python3-mistune | Yes 是 | Markdown parser Markdown 解析器 |
| python3-pygments | No 否 | Syntax highlighting 语法高亮 |
| katex (npm) | No 否 | LaTeX offline rendering LaTeX 离线渲染 |
| mermaid-cli (npm) | No 否 | Diagram rendering 图表渲染 |
Features / 功能
- Headings (h1–h3), bold, italic, inline code / 标题、加粗、斜体、行内代码
- Code blocks — line numbers, Monokai syntax highlighting (Pygments), auto word-wrap / 代码块—行号、Monokai 高亮、自动换行
- LaTeX — inline
$...$and display$$...$$(KaTeX CLI, offline) / LaTeX 公式—KaTeX CLI 离线渲染 - Mermaid diagrams (rendered as SVG) / Mermaid 图表—渲染为 SVG
- Unordered/ordered lists, blockquotes, horizontal rules, links, tables / 列表、引用、分割线、链接、表格
- 4 color themes: light, dark, sepia, nord / 4 种色彩主题
- Smart page splitting: none, A4, A5 (breaks at logical boundaries) / 智能分页
- Session-level auto-policy / Session 级自动策略
- JPEG output, self-contained (no CDN, no JS) / JPEG 输出,完全自包含
Architecture / 架构
Markdown → mistune → HTML
LaTeX → extracted → §placeholder§ → KaTeX CLI → restored
Mermaid → mmdc → SVG → embedded
→ [Primary / 主引擎] Playwright Chromium screenshot → JPEG
→ [Fallback / 备用] wkhtmltoimage → JPEG
→ [optional / 可选] Pillow page split → multiple JPEGs
