🥑 Auto MD2IMG Skill
Automatically converts Markdown content to images for sending in any messaging platform, improving reading experience.
✨ Features
- - 🖼️ Automatically converts Markdown to high-definition images
- 📄 Supports smart pagination, up to 500 lines per page
- 📏 New: Height-based pagination mode (line count independent, split by pixel height threshold)
- 🧱 Splits by content blocks, does not cut off headings, code blocks, tables, etc.
- 🔢 Automatically adds page number annotations
- 🀄 Perfect support for Chinese fonts
- 😊 Supports colored Emoji
- 🎨 GitHub-style rendering
- 📸 Auto-detect JPEG/PNG format, supports quality adjustment
- 🔍 Debug mode, output detailed logs and save pagination content
- ⚡ Background browser management, improved performance for repeated conversions
- 🧹 Automatic cache cleaning, privacy protection
📖 Usage
When you need to reply to users with Markdown formatted content:
Basic Usage
- 1. Save Markdown content to a temporary file (or pass string directly)
- Call
scripts/md_to_png.js to generate images - Send images to users using
<img> tags - Embed paths using corresponding image tags for different messaging platforms
- Fall back to sending plain text Markdown if image generation fails
Script Invocation
CODEBLOCK0
Parameter Description
| Parameter | Type | Required | Default | Description |
|---|
| INLINECODE2 | string | ✅ | - | Path to input Markdown file |
| INLINECODE3 |
string | ❌ | Current directory | Output image directory |
|
maxLinesPerPage | number | ❌ | 500 | Maximum lines per page (line-based pagination) |
|
imageQuality | number | ❌ | 80 | JPEG image quality (1-100) |
|
--height <px> | number | ❌ | - | Height-based pagination threshold in pixels. ≤0 disables pagination entirely (single output image). Overrides line-based pagination. |
|
--debug | flag | ❌ | - | Enable Debug mode, output detailed logs and save intermediate pagination content |
🔧 Configuration
Font Configuration
- - Default fonts: WenQuanYi Micro Hei, WenQuanYi Zen Hei, Noto CJK SC, Noto Color Emoji
- Supports system font fallback
Output Configuration
- - Output resolution: 2x (HD)
- Maximum width: 900px
- Automatically adapts to content height
- PNG format output
Pagination Configuration
- - Default maximum lines per page: 500 (line-based pagination)
- Height-based pagination: Split by pixel threshold (
--height parameter), independent of line count - Smart splitting by content blocks
- Does not cut off headings, code blocks, quotes, tables, lists
- Disable pagination entirely by setting INLINECODE9
Debug Mode
When enabled with
--debug flag:
- - Outputs detailed processing logs (content block detection, split points, rendering steps)
- Saves intermediate HTML render files for debugging
- Saves raw pagination split content as separate text files
- Includes timing metrics for performance analysis
📂 Script Paths
INLINECODE11 - Main Markdown to image tool
INLINECODE12 Functions:
- - Reads Markdown files
- Smart content block splitting
- HTML rendering
- Puppeteer screenshot
- Cache cleaning
🎯 Usage Examples
Example 1: Simple Conversion
CODEBLOCK1
Example 2: Usage in Chat Applications
CODEBLOCK2
Example 3: Height-based Pagination
CODEBLOCK3
Example 4: Debug Mode
CODEBLOCK4
🔒 Security Features
- - ✅ Path traversal protection (output directory whitelist)
- ✅ Filename sanitization (illegal character replacement)
- ✅ Content size limit (max 10MB)
- ✅ Line count range validation (10-10000)
- ✅ Configurable cache cleaning policy
📊 Performance Metrics
| Metric | Value |
|---|
| First browser startup | ~260ms |
| Small document conversion (200 words) |
~2.3s |
| Medium document conversion (2KB) | ~2.6s |
| Large document conversion (5KB) | ~3.6s |
| Repeated conversion performance improvement | 4.5% (single) / 50-70% (batch) |
🎨 Rendering Effects
Supported Markdown elements:
- - ✅ Headings (H1-H6)
- ✅ Text styles (bold, italic, strikethrough, inline code)
- ✅ Code blocks (syntax highlighting)
- ✅ Lists (ordered, unordered)
- ✅ Tables
- ✅ Quote blocks
- ✅ Links
- ✅ Images
- ✅ Emoji
🆕 New in v1.3.1
- - 📏 Height-based pagination mode (pixel-based splitting, no line count dependency)
- 📸 JPEG quality adjustment (1-100, balance between quality and file size)
- 🔍 Debug mode for troubleshooting conversion issues
- ⚡ 50%+ performance improvement for repeated conversions
- 🧹 More aggressive cache cleaning for better privacy
- 📁 Auto directory creation: Automatically creates output directories if they don't exist (no manual setup needed)
- 🐛 Fixed ENOENT error when output directory doesn't exist
- 🐛 Fixed "png screenshots do not support quality" error
- 🐛 Fixed JPEG quality setting not working issue
🛠️ Tech Stack
- - Node.js >= 14
- Puppeteer (headless browser)
- marked (Markdown parsing)
- GitHub style CSS
📝 Trigger Scenarios
All reply scenarios that require outputting Markdown formatted content:
- - Code snippet sharing
- Technical document replies
- Tabular data display
- List organization
- Long text formatting
- Use skill-cn.md when user inputs Chinese
⚠️ Notes
- 1. First conversion requires browser startup, slightly slower
- Recommend enabling
skipCacheClear configuration for batch conversions - Large documents may be split into multiple pages
- Image files occupy disk space, remember to clean up
Chinese Instructions (中文说明)
Usage
When you need to reply to users with Markdown formatted content:
- 1. First save Markdown content to a temporary file (or pass string directly)
- Call
scripts/md_to_png.js to generate images - Send images to users using
<img> tags - Embed paths using corresponding image tags for different messaging platforms
- Fall back to sending plain text Markdown if image generation fails
Script Path
scripts/md_to_png.js - Markdown to image tool
Configuration
- - Default fonts: WenQuanYi Micro Hei, WenQuanYi Zen Hei, Noto CJK SC, Noto Color Emoji
- Output resolution: 2x, clearer images
- Maximum width: 900px
- Automatically adapts to content height
- Default maximum lines per page: 500 lines
Auto MD2IMG Skill - Make Markdown replies more beautiful! 🎉
🥑 Auto MD2IMG 技能
自动将 Markdown 内容转换为图片,用于在任何消息平台发送,提升阅读体验。
✨ 功能特性
- - 🖼️ 自动将 Markdown 转换为高清图片
- 📄 支持智能分页,每页最多 500 行
- 📏 新增:基于高度的分页模式(不依赖行数,按像素高度阈值分割)
- 🧱 按内容块分割,不会截断标题、代码块、表格等
- 🔢 自动添加页码标注
- 🀄 完美支持中文字体
- 😊 支持彩色 Emoji
- 🎨 GitHub 风格渲染
- 📸 自动检测 JPEG/PNG 格式,支持质量调整
- 🔍 调试模式,输出详细日志并保存分页内容
- ⚡ 后台浏览器管理,提升重复转换性能
- 🧹 自动缓存清理,保护隐私
📖 使用方法
当需要向用户回复 Markdown 格式内容时:
基本用法
- 1. 将 Markdown 内容保存到临时文件(或直接传递字符串)
- 调用 scripts/mdtopng.js 生成图片
- 使用
标签向用户发送图片 - 根据不同消息平台使用对应的图片标签嵌入路径
- 如果图片生成失败,则回退到发送纯文本 Markdown
脚本调用
bash
基本用法
node scripts/md
topng.js input.md
指定输出目录
node scripts/md
topng.js input.md ./output
自定义每页行数
node scripts/md
topng.js input.md ./output 300
自定义 JPEG 质量(1-100,默认 80)
node scripts/md
topng.js input.md ./output 300 75
基于高度的分页(自定义高度阈值,单位像素,例如 2000px)
node scripts/md
topng.js input.md ./output --height 2000
完全禁用分页(输出单张图片)
node scripts/md
topng.js input.md ./output --height 0
启用调试模式(输出详细日志 + 保存分页内容)
node scripts/md
topng.js input.md ./output --debug
参数说明
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|
| inputFile | string | ✅ | - | 输入 Markdown 文件路径 |
| outputDir |
string | ❌ | 当前目录 | 输出图片目录 |
| maxLinesPerPage | number | ❌ | 500 | 每页最大行数(基于行数的分页) |
| imageQuality | number | ❌ | 80 | JPEG 图片质量(1-100) |
| --height
| number | ❌ | - | 基于高度的分页阈值(像素)。≤0 时完全禁用分页(输出单张图片)。会覆盖基于行数的分页。 |
| --debug | 标志 | ❌ | - | 启用调试模式,输出详细日志并保存中间分页内容 |
🔧 配置
字体配置
- - 默认字体:文泉驿微米黑、文泉驿正黑、Noto CJK SC、Noto Color Emoji
- 支持系统字体回退
输出配置
- - 输出分辨率:2x(高清)
- 最大宽度:900px
- 自动适应内容高度
- PNG 格式输出
分页配置
- - 默认每页最大行数:500(基于行数的分页)
- 基于高度的分页:按像素阈值分割(--height 参数),不依赖行数
- 按内容块智能分割
- 不会截断标题、代码块、引用、表格、列表
- 设置 --height 0 可完全禁用分页
调试模式
使用 --debug 标志启用时:
- - 输出详细处理日志(内容块检测、分割点、渲染步骤)
- 保存中间 HTML 渲染文件用于调试
- 将原始分页分割内容保存为单独的文本文件
- 包含性能分析的时间指标
📂 脚本路径
scripts/mdtopng.js - 主要的 Markdown 转图片工具
scripts/mdtopng.js 功能:
- - 读取 Markdown 文件
- 智能内容块分割
- HTML 渲染
- Puppeteer 截图
- 缓存清理
🎯 使用示例
示例 1:简单转换
javascript
import { exec } from child_process;
import path from path;
const markdownContent = # Hello World\n\n这是测试内容。;
// 保存到临时文件
const tempFile = path.join(/tmp, temp.md);
fs.writeFileSync(tempFile, markdownContent);
// 调用转换脚本
exec(node scripts/mdtopng.js ${tempFile}, (error, stdout, stderr) => {
if (error) {
console.error(转换失败:, error);
return;
}
console.log(转换成功:, stdout);
});
示例 2:在聊天应用中使用
javascript
// 当需要回复 Markdown 内容时
async function replyWithMarkdown(content, outputDir) {
try {
// 调用 md2img 转换
const baseName = reply_${Date.now()};
const files = await convertMarkdown(content, outputDir, baseName);
// 使用
标签发送图片
for (const file of files) {
await sendMessage(
);
}
} catch (error) {
// 失败时回退到纯文本
await sendMessage(content);
}
}
示例 3:基于高度的分页
bash
按 2000px 高度分割,适合移动端查看
node scripts/mdtopng.js long_article.md ./output --height 2000
不分页,输出单张长图
node scripts/mdtopng.js short_note.md ./output --height 0
调整 JPEG 质量以加快分享速度
node scripts/mdtopng.js report.md ./output 500 60 --height 1500
示例 4:调试模式
bash
调试模式,用于排查转换问题
node scripts/mdtopng.js problem_content.md ./output --debug
🔒 安全特性
- - ✅ 路径遍历防护(输出目录白名单)
- ✅ 文件名净化(非法字符替换)
- ✅ 内容大小限制(最大 10MB)
- ✅ 行数范围验证(10-10000)
- ✅ 可配置的缓存清理策略
📊 性能指标
| 指标 | 数值 |
|---|
| 首次浏览器启动 | ~260ms |
| 小文档转换(200 字) |
~2.3s |
| 中等文档转换(2KB) | ~2.6s |
| 大文档转换(5KB) | ~3.6s |
| 重复转换性能提升 | 4.5%(单次)/ 50-70%(批量) |
🎨 渲染效果
支持的 Markdown 元素:
- - ✅ 标题(H1-H6)
- ✅ 文本样式(加粗、斜体、删除线、行内代码)
- ✅ 代码块(语法高亮)
- ✅ 列表(有序、无序)
- ✅ 表格
- ✅ 引用块
- ✅ 链接
- ✅ 图片
- ✅ Emoji
🆕 v1.3.1 新增功能
- - 📏 基于高度的分页模式(按像素分割,不依赖行数)
- 📸 JPEG 质量调整(1-100,在质量和文件大小之间取得平衡)
- 🔍 调试模式,用于排查转换问题
- ⚡ 重复转换性能提升 50% 以上
- 🧹 更积极的缓存清理,更好的隐私保护
- 📁 自动创建目录:如果输出目录不存在,自动创建(无需手动设置)
- 🐛 修复输出目录不存在时的 ENOENT 错误
- 🐛 修复png 截图不支持质量错误
- 🐛 修复 JPEG 质量设置不生效的问题
🛠️ 技术栈
- - Node.js >= 14
- Puppeteer(无头浏览器)
- marked(Markdown 解析)
- GitHub 风格 CSS
📝 触发场景
所有需要输出 Markdown 格式内容的回复场景:
- - 代码片段分享
- 技术文档回复
- 表格数据展示
- 列表整理
- 长文本格式化
- 用户输入中文时使用 skill-cn.md
⚠️ 注意事项
1.