Markdown-Formatter - Beautify Your Markdown
Vernox Utility Skill - Make your markdown look professional.
Overview
Markdown-Formatter is a powerful tool for formatting, linting, and beautifying markdown documents. Supports multiple style guides (CommonMark, GitHub Flavored Markdown, custom rules) and handles everything from simple cleanup to complex reformatting.
Features
✅ Formatter Engine
- - Multiple style guides (CommonMark, GitHub, custom)
- Preserves document structure
- Handles nested lists, code blocks, tables
- Configurable line width and indentation
- Smart heading normalization
- Link reference optimization
✅ Linting & Cleanup
- - Remove trailing whitespace
- Normalize line endings (LF vs CRLF)
- Fix inconsistent list markers
- Remove empty lines at end
- Fix multiple consecutive blank lines
✅ Beautification
- - Improve heading hierarchy
- Optimize list formatting
- Format code blocks with proper spacing
- Wrap long lines at configured width
- Add proper spacing around emphasis
✅ Validation
- - Check markdown syntax validity
- Report linting errors
- Suggest improvements
- Validate links and references
Installation
CODEBLOCK0
Quick Start
Format a Document
CODEBLOCK1
Beautify Multiple Files
CODEBLOCK2
Lint and Fix
CODEBLOCK3
Tool Functions
formatMarkdown
Format markdown content according to style guide.
Parameters:
- -
markdown (string, required): Markdown content to format - INLINECODE2 (string, required): Style guide name ('commonmark', 'github', 'commonmark', 'custom')
- INLINECODE3 (object, optional):
-
maxWidth (number): Line wrap width (default: 80)
-
headingStyle (string): 'atx' | 'setext' | 'underlined' | 'consistent' (default: 'atx')
-
listStyle (string): 'consistent' | 'dash' | 'asterisk' | 'plus' (default: 'consistent')
-
codeStyle (string): 'fenced' | 'indented' (default: 'fenced')
-
emphasisStyle (string): 'underscore' | 'asterisk' (default: 'asterisk')
-
strongStyle (string): 'asterisk' | 'underline' (default: 'asterisk')
-
linkStyle (string): 'inline' | 'reference' | 'full' (default: 'inline')
-
preserveHtml (boolean): Keep HTML as-is (default: false)
-
fixLists (boolean): Fix inconsistent list markers (default: true)
-
normalizeSpacing (boolean): Fix spacing around formatting (default: true)
Returns:
- -
formattedMarkdown (string): Formatted markdown - INLINECODE15 (array): Array of warning messages
- INLINECODE16 (object): Formatting statistics
- INLINECODE17 (object): Linting errors and fixes
- INLINECODE18 (number): Original character count
- INLINECODE19 (number): Formatted character count
formatBatch
Format multiple markdown files at once.
Parameters:
- -
markdownFiles (array, required): Array of file paths - INLINECODE22 (string): Style guide name
- INLINECODE23 (object, optional): Same as formatMarkdown options
Returns:
- -
results (array): Array of formatting results - INLINECODE25 (number): Number of files processed
- INLINECODE26 (number): Total warnings across all files
- INLINECODE27 (number): Time taken in ms
lintMarkdown
Check markdown for issues without formatting.
Parameters:
- -
markdown (string, required): Markdown content to lint - INLINECODE30 (string): Style guide name
- INLINECODE31 (object, optional): Additional linting options
-
checkLinks (boolean): Validate links (default: true)
-
checkHeadingLevels (boolean): Check heading hierarchy (default: true)
-
checkListConsistency (boolean): Check list marker consistency (default: true)
-
checkEmphasisBalance (boolean): Check emphasis pairing (default: false)
Returns:
- -
errors (array): Array of error objects - INLINECODE37 (array): Array of warning objects
- INLINECODE38 (object): Linting statistics
- INLINECODE39 (array): Suggested fixes
Style Guides
CommonMark (default)
- - Standard CommonMark specification
- ATX headings (ATX-style)
- Reference-style links [text]
- Underscore emphasis
- Asterisk emphasis
GitHub Flavored Markdown
- - Fenced code blocks with \
\\
- Tables with pipes
- Task lists [ ] with x
- Strikethrough ~~text~~
- Autolinks with <https://url>
### Consistent (default)
- Consistent ATX heading levels
- Consistent list markers
- Consistent emphasis style
- Consistent code block style
### Custom
- User-defined rules
- Regex-based transformations
- Custom heading styles
## Use Cases
### Documentation Cleanup
- Fix inconsistent formatting in README files
- Normalize heading styles
- Fix list markers
- Clean up extra whitespace
### Content Creation
- Format articles with consistent style
- Beautify blog posts before publishing
- Ensure consistent heading hierarchy
### Technical Writing
- Format code documentation
- Beautify API specs
- Clean up messy markdown from LLMs
### README Generation
- Format and beautify project README files
- Ensure consistent structure
- Professional appearance for open source
### Markdown Conversion
- Convert HTML to markdown
- Reformat from one style to another
- Extract and format markdown from other formats
## Configuration
### Edit config.json`:
CODEBLOCK4
Examples
Simple Formatting
CODEBLOCK5
Complex Beautification
CODEBLOCK6
Linting and Fixing
CODEBLOCK7
Batch Processing
CODEBLOCK8
Performance
Speed
- - Small documents (<1000 words): <50ms
- Medium documents (1000-5000 words): 50-200ms
- Large documents (5000+ words): 200-500ms
Accuracy
- - Structure preservation: 100%
- Style guide compliance: 95%+
- Whitespace normalization: 100%
Error Handling
Invalid Input
- - Clear error message
- Suggest checking file path
- Validate markdown content before formatting
Markdown Parsing Errors
- - Report parsing issues clearly
- Suggest manual fixes
- Graceful degradation on errors
File I/O Errors
- - Clear error with file path
- Check file existence
- Suggest permissions fix
- Batch processing continues on errors
Troubleshooting
Format Not Applied
- - Check if style is correct
- Verify options are respected
- Check for conflicting rules
- Test with simple example
Linting Shows Too Many Errors
- - Some errors are style choices, not real issues
- Consider disabling specific checks
- Use custom rules for specific needs
Tips
Best Results
- - Use consistent style guide
- Enable fixLists, normalizeSpacing options
- Set maxWidth appropriate for your output medium
- Test on small samples first
Performance Optimization
- - Process large files in batches
- Disable unused linting checks
- Use simpler rules for common patterns
License
MIT
Format markdown. Keep your docs beautiful. 🔮
Markdown-Formatter - 美化你的Markdown文档
Vernox实用技能 - 让你的Markdown看起来更专业。
概述
Markdown-Formatter是一款功能强大的工具,用于格式化、检查并美化Markdown文档。支持多种样式指南(CommonMark、GitHub Flavored Markdown、自定义规则),可处理从简单清理到复杂重新格式化的各种需求。
功能特性
✅ 格式化引擎
- - 多种样式指南(CommonMark、GitHub、自定义)
- 保留文档结构
- 处理嵌套列表、代码块、表格
- 可配置的行宽和缩进
- 智能标题规范化
- 链接引用优化
✅ 检查与清理
- - 删除尾部空白
- 规范化换行符(LF vs CRLF)
- 修复不一致的列表标记
- 删除末尾空行
- 修复多个连续空行
✅ 美化功能
- - 优化标题层级
- 优化列表格式
- 使用适当间距格式化代码块
- 按配置宽度换行
- 在强调内容周围添加适当间距
✅ 验证功能
- - 检查Markdown语法有效性
- 报告检查错误
- 提供改进建议
- 验证链接和引用
安装
bash
clawhub install markdown-formatter
快速开始
格式化文档
javascript
const result = await formatMarkdown({
markdown: # 我的文档\n\n\n## 第一节\n此处为内容...,
style: github,
options: {
maxWidth: 80,
headingStyle: atx
}
});
console.log(result.formattedMarkdown);
美化多个文件
javascript
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} 个警告);
});
检查并修复
javascript
const result = await lintMarkdown({
markdown: # 我的文档\n\n\n错误列表\n\n- 项目1\n- 项目2,
style: github
});
console.log(发现错误:${result.errors});
console.log(已修复:${result.fixed});
工具函数
formatMarkdown
根据样式指南格式化Markdown内容。
参数:
- - markdown(字符串,必填):要格式化的Markdown内容
- style(字符串,必填):样式指南名称(commonmark、github、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(数组):建议修复
样式指南
CommonMark(默认)
- - 标准CommonMark规范
- ATX标题
- 引用式链接[文本]
- 下划线强调
- 星号强调
GitHub Flavored Markdown
- - 使用\\\的围栏代码块
- 带管道的表格
- 带x的任务列表[ ]
- 删除线~~文本~~
- 自动链接
Consistent(默认)
- - 一致的ATX标题级别
- 一致的列表标记
- 一致的强调样式
- 一致的代码块样式
自定义
- - 用户定义的规则
- 基于正则表达式的转换
- 自定义标题样式
使用场景
文档清理
- - 修复README文件中不一致的格式
- 规范化标题样式
- 修复列表标记
- 清理多余空白
内容创作
- - 以一致样式格式化文章
- 发布前美化博客文章
- 确保一致的标题层级
技术写作
- - 格式化代码文档
- 美化API规范
- 清理来自LLM的混乱Markdown
README生成
- - 格式化并美化项目README文件
- 确保结构一致
- 为开源项目提供专业外观
Markdown转换
- - 将HTML转换为Markdown
- 从一种样式重新格式化为另一种
- 从其他格式提取并格式化Markdown
配置
编辑config.json:
json
{
defaultStyle: github,
maxWidth: 80,
headingStyle: atx,
listStyle: consistent,
codeStyle: fenced,
emphasisStyle: asterisk,
linkStyle: inline,
customRules: [],
linting: {
checkLinks: true,
checkHeadingLevels: true,
checkListConsistency: true
}
}
示例
简单格式化
javascript
const result = await formatMarkdown({
markdown: # 我的标题\n\n\n这是内容。,
style: github
});
console.log(result.formattedMarkdown);
复杂美化
javascript
const result = await formatMarkdown({
markdown: # 标题1\n## 标题2\n\n段落...,
style: github,
options: {
fixLists: true,
normalizeSpacing: true,
wrapWidth: 80
}
});
console.log(result.formattedMarkdown);
检查与修复
javascript
const result = await lintMarkdown({
markdown: # 标题\n\n- 项目1\n- 项目2\n\n## 第二节,
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
});
批量处理
javascript
const results = await formatBatch({
markdownFiles: [./doc1.md, ./doc2.md, ./README.md],
style: github
});
console.log(已处理 ${results.totalFiles} 个文件);
console.log(总警告数:${results.totalWarnings});
性能
速度
- - 小型文档(<1000字):<50ms
- 中型文档(1000-5000字):50-200ms