名称: markdown-formatter
描述: 使用可配置的样式格式化和美化 Markdown 文档。保持结构,修复格式,确保一致性。
元数据:
{
"openclaw":
{
"version": "1.0.0",
"author": "Vernox",
"license": "MIT",
"tags": ["markdown", "formatter", "beautifier", "text", "formatting", "documentation"],
"category": "tools"
}
}
Vernox 实用工具技能 - 让你的 Markdown 文档更专业。
Markdown-Formatter 是一个功能强大的工具,用于格式化、检查和美化 Markdown 文档。它支持多种样式指南(CommonMark、GitHub Flavored Markdown、自定义规则),并能处理从简单清理到复杂重构的所有任务。
clawhub install markdown-formatter
const result = await formatMarkdown({
markdown: '# My Document\n\n\n## Section 1\nContent here...',
style: 'github',
options: {
maxWidth: 80,
headingStyle: 'atx'
}
});
console.log(result.formattedMarkdown);
const results = await formatBatch({
markdownFiles: ['./doc1.md', './doc2.md', './README.md'],
style: 'github',
options: { wrapWidth: 80 }
});
results.forEach(result => {
console.log(`${result.file}: ${result.warnings} 条警告`);
});
const result = await lintMarkdown({
markdown: '# My Document\n\n\nBad list\n\n- item 1\n- item 2',
style: 'github'
});
console.log(`发现错误: ${result.errors}`);
console.log(`已修复: ${result.fixed}`);
formatMarkdown根据样式指南格式化 Markdown 内容。
参数:
- markdown (字符串,必需): 要格式化的 Markdown 内容
- style (字符串,必需): 样式指南名称('commonmark'、'github'、'commonmark'、'custom')
- options (对象,可选):
- maxWidth (数字): 行换行宽度(默认: 80)
- headingStyle (字符串): 'atx' | 'setext' | 'underlined' | 'consistent'(默认: 'atx')
- listStyle (字符串): 'consistent' | 'dash' | 'asterisk' | 'plus'(默认: 'consistent')
- codeStyle (字符串): 'fenced' | 'indented'(默认: 'fenced')
- emphasisStyle (字符串): 'underscore' | 'asterisk'(默认: 'asterisk')
- strongStyle (字符串): 'asterisk' | 'underline'(默认: 'asterisk')
- linkStyle (字符串): 'inline' | 'reference' | 'full'(默认: 'inline')
- preserveHtml (布尔值): 保持 HTML 原样(默认: false)
- fixLists (布尔值): 修复不一致的列表标记(默认: true)
- normalizeSpacing (布尔值): 修复格式周围的间距(默认: true)
返回值:
- formattedMarkdown (字符串): 格式化后的 Markdown
- warnings (数组): 警告消息数组
- stats (对象): 格式化统计信息
- lintResult (对象): 检查错误和修复结果
- originalLength (数字): 原始字符数
- formattedLength (数字): 格式化后的字符数
formatBatch一次性格式化多个 Markdown 文件。
参数:
- markdownFiles (数组,必需): 文件路径数组
- style (字符串): 样式指南名称
- options (对象,可选): 与 formatMarkdown 选项相同
返回值:
- results (数组): 格式化结果数组
- totalFiles (数字): 已处理的文件总数
- totalWarnings (数字): 所有文件的总警告数
- processingTime (数字): 处理时间(毫秒)
lintMarkdown检查 Markdown 问题但不进行格式化。
参数:
- markdown (字符串,必需): 要检查的 Markdown 内容
- style (字符串): 样式指南名称
- options (对象,可选): 额外的检查选项
- checkLinks (布尔值): 验证链接(默认: true)
- checkHeadingLevels (布尔值): 检查标题层级(默认: true)
- checkListConsistency (布尔值): 检查列表标记一致性(默认: true)
- checkEmphasisBalance (布尔值): 检查强调符号配对(默认: false)
返回值:
- errors (数组): 错误对象数组
- warnings (数组): 警告对象数组
- stats (对象): 检查统计信息
- suggestions (数组): 建议的修复方案
~~文本~~config.json:{
"defaultStyle": "github",
"maxWidth": 80,
"headingStyle": "atx",
"listStyle": "consistent",
"codeStyle": "fenced",
"emphasisStyle": "asterisk",
"linkStyle": "inline",
"customRules": [],
"linting": {
"checkLinks": true,
"checkHeadingLevels": true,
"checkListConsistency": true
}
}
const result = await formatMarkdown({
markdown: '# 我的标题\n\n\n这是内容。',
style: 'github'
});
console.log(result.formattedMarkdown);
const result = await formatMarkdown({
markdown: '# 标题 1\n## 标题 2\n\n段落...',
style: 'github',
options: {
fixLists: true,
normalizeSpacing: true,
wrapWidth: 80
}
});
console.log(result.formattedMarkdown);
const result = await lintMarkdown({
markdown: '# 标题\n\n- 项目 1\n- 项目 2\n\n## 第 2 节',
style: 'github'
});
console.log(`错误数: ${result.errors.length}`);
result.errors.forEach(err => {
console.log(` - ${err.message} 在第 ${err.line} 行`);
});
// 自动修复
const fixed = await formatMarkdown({
markdown: result.fixed,
style: 'github'
});
const results = await formatBatch({
markdownFiles: ['./doc1.md', './doc2.md', './README.md'],
style: 'github'
});
console.log(`已处理 ${results.totalFiles} 个文件`);
console.log(`总警告数: ${results.totalWarnings}`);
MIT
格式化 Markdown。让你的文档保持美观。 🔮