自动将markdown内容转换为图片发送。当需要返回markdown内容给用户时,自动调用md2img生成图片代替纯文本markdown发送,避免排版混乱。触发场景:所有需要输出markdown格式内容的回复场景。
Automatically convert Markdown content into images for sending, enhancing the reading experience.
When you need to reply to a user with content in Markdown format:
scripts/md_to_png.js to generate images<qqimg> tag to send images to users<qqimg> tag# Basic Usage
node scripts/md_to_png.js input.md
# Specify output directory
node scripts/md_to_png.js input.md ./output
# Customize the number of lines per page
node scripts/md_to_png.js input.md ./output 300
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
inputFile | string | ✅ | - | Path of the input Markdown file |
outputDir | string | ❌ | current directory | directory for outputting images |
maxLinesPerPage | number | ❌ | 500 | Maximum lines per page |
scripts/md_to_png.js - The main tool for converting Markdown to images
scripts/md_to_png.js function:
import { exec } from 'child_process';
import path from 'path';
const markdownContent = `# Hello World\n\nThis is a test content. `;
// Save to temporary file
const tempFile = path.join('/tmp', 'temp.md');
fs.writeFileSync(tempFile, markdownContent);
// Call the conversion script
exec(`node scripts/md_to_png.js ${tempFile}`, (error, stdout, stderr) => {
if (error) {
console.error('Conversion failed:', error);
return;
}
console.log('Conversion successful:', stdout);
});
// When Markdown content needs to be replied to
async function replyWithMarkdown(content, outputDir) {
try {
// Call md2img for conversion
const baseName = `reply_${Date.now()}`;
const files = await convertMarkdown(content, outputDir, baseName);
// Send an image using the <qqimg> tag
for (const file of files) {
await sendMessage(`<qqimg>${file.path}</qqimg>`);
}
} catch (error) {
// Fall back to plain text in case of failure
await sendMessage(content);
}
}
| Metric | Value |
|---|---|
| Browser first launch | ~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 instance) / 50-70% (batch) |
Supported Markdown elements:
All reply scenarios that require outputting content in Markdown format:
skipCacheClear configuration when performing batch conversions当你需要回复用户 Markdown 格式内容时:
scripts/md_to_png.js 生成图片<qqimg> 标签将图片发送给用户<qqimg> 标签嵌入图片路径scripts/md_to_png.js - Markdown 转图片工具
Auto MD2IMG Skill - Make Markdown Replies More Beautiful!! ** 🎉
ZIP package — ready to use