使用说明
MD转换器
版本: 2.1.0
状态: 生产就绪
使用YAML前体、严格验证、智能分节和专业Word样式将Markdown文件转换为DOCX、XLSX和PPTX格式。包括CLI和MCP(模型上下文协议)服务器接口。
为什么这很重要:启用IDE优先咨询
创新
虽然大多数顾问在传统的办公套件(Word、Excel、PowerPoint)中工作,并从ChatGPT或Copilot复制粘贴,但有一个 更有效的方法 等待解锁:
在人工智能的帮助下,完全在IDE中工作,然后自动生成客户端可交付成果。
当前的咨询现实
标准工作流程(2024-2025):
- 用Word或PowerPoint书写
- 从ChatGPT/Copilot复制粘贴
- 手动格式化和清理
- 通过文件名进行版本控制
- 通过电子邮件附件进行协作
限制:
- 工具之间的上下文切换会中断流程
- 手动格式化很耗时
- 版本控制混乱
- 人工智能辅助是分散的
IDE第一选择
该工具支持一种新方法:
- 用Markdown思考和写作 -干净、版本控制、基于Git的协作
- 利用嵌入式人工智能 -Cursor中的Claude在您的工作流程中提供实时帮助
- 纯文本工作 -快速、轻便、强大
- 单一事实来源 -Markdown为主,生成输出
- 保持流畅 -无需切换到办公应用程序
挑战
客户和利益相关者需要 传统格式 (Word、Excel、PowerPoint):
- 行政简报需要Word文档
- 财务模型需要Excel工作簿
- 演示文稿需要PowerPoint演示文稿
手动转换会破坏IDE工作流程并浪费时间。
解决方案:MD转换器MCP
从IDE到客户端交付成果的无缝桥梁:
- 在Markdown中工作 -完整的IDE功能、AI辅助、版本控制
- 在YAML中添加元数据 -专业文档属性
- 一个命令转换 -即时专业Word/Excel/PowerPoint
- 内置验证 -质量保证确保一致性
- 智能排除 -系统文件、注释、参考文献保留在markdown中
结果: 你保持流畅,客户得到专业的交付成果。
为什么这种方法更快
传统工作流程:
- AI工具中的草稿→ 复制到Word→ 格式→ 审查→ 修改(在Word中重复)
IDE第一个工作流程:
- 使用AI在IDE中起草→ 在IDE中使用AI进行修改→ 转换→ Done
优势:
- ✅ 所有工作的单一环境
- ✅ AI上下文在整个文档生命周期中持续存在
- ✅ 内置版本控制(Git)
- ✅ 自动应用一致的格式
- ✅ 无需手动复制粘贴
- ✅ Markdown是可移植的,面向未来
现实世界咨询示例
挑战: 为企业客户提供全面的战略规划
- 20多份规划文件,涵盖战略、架构、交付、预算
- 高管决策执行简报
- 多年期方案的财务模式
- 需要专业格式(公司分类、适当的元数据)
解决方案:
- 所有计划都在Markdown中完成,并在IDE中借助人工智能
- YAML是分类、版本和作者的首要问题
- 单一命令:
md-convert "**/*.md"→ 15 DOCX+1 XLSX - 智能排除参考材料和系统文件
- 独立格式化的主要边界处的分段
- 与客户端模板兼容的专业Word样式
结果:
- 计划在几天内完成,而不是几周
- 所有文档均采用专业格式
- 跨交付成果的一致元数据
- 已准备好执行分配
特性
🚀 2.1.0版本增强功能
YAML前端支持
- 14个元数据字段(格式、标题、作者、日期、分类、版本、状态等)
- 自动映射到Word/Excel/PowerPoint中的文档属性
- 格式检测(docx、xlsx、pptx或其组合)
- 文档类型分类(文档、电子邮件、参考、注释、系统)
严格的文档验证
- 标题层次结构验证(无跳过级别)
- 表结构一致性检查
- 空航向检测
- 元数据完整性警告
- 可选的
--strict生产文件模式
智能分段断路器
- DOCX:
section_breaks: auto仅创建##H2之前的部分(主要边界) - PPTX:
slide_breaks: h1|h2|hr控制幻灯片创建 - 减少不必要的分段中断
- 启用独立的节格式
智能排除规则
- 基于路径:自动排除README、/notes/、/references/
- 前件:
convert: false或document_type: email|reference|note|system - 更清洁的批量转换
- 在输出中明确跳过原因
专业单词样式
- 内置样式:普通、标题1-6、列表段落
- 字符样式:强(粗体),强调(斜体)
- 模板兼容
- 易于批量重新格式化
已修复编号列表
- 正确的单词编号配置
- 顺序编号(1、2、3…)
- 不再有DOCX损坏
XLSX富文本
- 粗体文本(
**text**)在Excel中正确呈现 - 斜体文本(
*text*)正确渲染 - 单元格中的混合格式可以正常工作
📄 多种输出格式
- 文档:具有正确格式、标题、表格、列表和代码块的Word文档
- XLSX 文件:具有公式支持、数据类型检测和格式设置的Excel电子表格
- 演示文稿:具有自动幻灯片布局的PowerPoint演示文稿
🔢 Excel公式支持
- 转换
{=FORMULA}Markdown表中的语法到实际的Excel公式 - 支持60多种Excel函数(SUM、AVERAGE、IF、VLOOKUP等)
- 自动数据类型检测(数字、日期、布尔值、文本)
- 细胞参考验证
🤖 双接口
- 命令行界面:用于批处理的命令行工具
- MCP服务器:与Cursor中的Claude等人工智能助手集成
🎨 格式选项
- 可定制的字体和大小
- Excel中列的自动宽度
- 冻结的标题行
- 演示文稿的浅色/深色主题
- 澳大利亚日期格式(日/月/年)
安装
# Clone or navigate to the repository
cd /path/to/md_converter
# Install dependencies
npm install
# Build the project
npm run build
快速开始
1.在Markdown中添加前置内容
---
format: docx
title: "Executive Brief - AI Strategy"
author: "Dale Rogers"
date: "2025-11-10"
classification: "OFFICIAL"
version: "1.0"
status: final
keywords: ["AI", "strategy", "executive"]
section_breaks: auto
---
# Executive Brief
Your content here...
2.转换为Word
md-convert document.md --format docx
3.审查输出
- 打开生成的
.docx文件 - 检查文件→ Info → 元数据的属性
- 在主页中验证样式→ 样式窗格
- 检查分段中断(查看→ 草稿模式)
YAML前体参考
必填字段
format: docx # docx, xlsx, pptx, or combinations
title: "Document Title" # Document title (used in properties)
扩展字段(推荐)
author: "Your Name" # Creator/author name
date: "2025-11-10" # Document date (YYYY-MM-DD)
classification: "OFFICIAL" # Security classification
version: "1.0" # Version number
status: final # draft|review|approved|final
description: "Brief description" # Document description (<250 chars)
keywords: ["key1", "key2"] # Search keywords (array)
subject: "Category" # Document subject/category
文档控制字段
convert: false # Skip conversion (default: true)
document_type: reference # document|email|reference|note|system
格式化特定字段
# DOCX only
section_breaks: auto # auto|all|none
# PPTX only
slide_breaks: h2 # h1|h2|hr
排除规则
基于路径的排除(自动)
这些文件会自动跳过:
README.md(任何位置,不区分大小写)- 文件在
/notes/目录 - 文件在
/reference/或/references/目录
前体排除
方法1:显式标志
convert: false
方法2:文档类型(自动)
document_type: email # Auto-skips: email, reference, note, system
输出示例
Found 24 file(s) to convert
Skipping: README.md (excluded by path pattern)
Skipping: notes/meeting-notes.md (excluded by path pattern)
Converting: EXECUTIVE_BRIEF.md
✓ DOCX: EXECUTIVE_BRIEF.docx
Converting: budget.md
⊘ Skipped (document_type: reference)
Conversion Summary:
✓ Success: 18
⊘ Skipped: 6
分段中断规则(DOCX)
控制方式 --- 处理水平规则:
section_breaks: auto (推荐)
规则: 仅当满足以下条件时才进行分段 --- 紧随其后的是 ## H2
例子:
## Major Section A
Content here...
---
## Major Section B
New section with independent formatting
结果: 已创建分节符(可以有不同的页眉/页脚)
Content here...
---
More content in same section (just visual divider)
结果: 仅限视觉分隔符(无分段)
section_breaks: all
每 --- 创建Word分节符。
在以下情况下使用: 需要对节格式进行最大程度的控制
section_breaks: none
全部 --- 它们只是视觉上的分隔物。
在以下情况下使用: 简单的文档,不需要独立的部分
滑裂规则(PPTX)
控制何时创建新幻灯片:
slide_breaks: h2 (默认)
每次都有新幻灯片 # H1 和 ## H2
最适合: 标准演示文稿,章节清晰
slide_breaks: h1
新幻灯片仅在 # H1
最适合: 每张幻灯片包含更多内容的密集演示文稿
slide_breaks: hr
每次都有新幻灯片 --- 水平线
最适合: 手动控制滑裂
CLI使用情况
基本转换
# Convert to DOCX (Word)
md-convert input.md --format docx
# Convert to XLSX (Excel) - tables only
md-convert input.md --format xlsx
# Convert to PPTX (PowerPoint)
md-convert input.md --format pptx
# Convert to all formats
md-convert input.md --format all
批处理
# Convert all markdown files
md-convert "**/*.md" --format docx
# Convert with output directory
md-convert "./docs/**/*.md" --format all --output-dir ./exports
验证
# Standard mode (shows warnings, continues)
md-convert document.md --format docx
# Strict mode (fails on warnings)
md-convert document.md --format docx --strict
# Skip validation (faster, not recommended)
md-convert document.md --format docx --no-validate
选项
# XLSX options
md-convert report.md --format xlsx --freeze-headers --auto-width
# PPTX options
md-convert slides.md --format pptx --theme dark
# Font options
md-convert document.md --format docx --font-family "Calibri" --font-size 11
命令
# Preview table extraction
md-convert preview report.md
# Validate formulas
md-convert validate report.md
# Start MCP server
md-convert serve
MCP服务器使用情况
在游标中配置
增添 .cursor/mcp.json:
{
"mcpServers": {
"md-converter": {
"command": "node",
"args": [
"/Users/dalerogers/Projects/active/experimental/md_converter/dist/cli/index.js",
"serve"
],
"disabled": false
}
}
}
可用的MCP工具
- 转换为docx -将Markdown转换为Word文档
- 转换为xlsx -使用公式将Markdown表格转换为Excel
- 转换为ptx -将Markdown转换为PowerPoint演示文稿
- preview_tables -预览表格提取和公式
- validate_formulas -验证公式语法
在Cursor中与Claude一起使用
You: "Convert this markdown to Word"
Claude: [Uses convert_md_to_docx tool]
You: "Create Excel from these budget tables"
Claude: [Uses convert_md_to_xlsx tool]
好处: 无缝转换,无需离开IDE工作流程。
Word文档功能
应用的样式
段落样式:
Normal-正文(所有内容的基本样式)Heading 1通过Heading 6-结构标题ListParagraph-所有列表项(项目符号和编号)
字符样式:
Strong-粗体文本(**text**)Emphasis-斜体文本(*text*)
优点:
- ✅ 与公司Word模板兼容
- ✅ 易于批量重新格式化(更改普通样式→ 所有文本更新)
- ✅ 遵循Microsoft Word最佳实践
- ✅ 专业形象
分段断裂
文档在主要边界处分为Word部分:
每节特征:
- 独立的页眉和页脚
- 不同的页码(重新开始或不同样式)
- 不同的页面方向(纵向/横向混合)
- 不同的利润
- 不同的页面大小
查看分段:
- View → 草稿模式→ 显示“分节(下一页)”
- 状态栏显示“Y的X部分”
Excel工作簿功能
表转换
每个markdown表都变成一个单独的工作表:
特征:
- 灰色背景和粗体文本的标题
- 冻结标题行(滚动数据,标题保持可见)
- 自动调整列的宽度(自动适应内容)
- 适当的边界和网格线
公式支持
使用 {=FORMULA} 在markdown表中:
| Product | Price | Qty | Total |
|---------|-------|-----|-------|
| Apples | 2.50 | 10 | {=B2*C2} |
| Oranges | 3.00 | 5 | {=B3*C3} |
| **Total** | | | {=SUM(D2:D3)} |
转换为自动计算的实际Excel公式。
支援多文本格式编写
markdown的粗体和斜体格式:
| Item | Value |
|------|-------|
| **Total Cost** | $1,500 |
| *Estimated* | $1,200 |
结果: 粗体和斜体文本在Excel单元格中正确显示。
PowerPoint演示文稿功能
滑动结构
标题和水平规则控制幻灯片打断:
# Main Title
Presentation subtitle
---
## Section Header Slide
---
### Content Slide
- Bullet point 1
- Bullet point 2
---
映射:
# H1→ 标题幻灯片## H2→ 节标题幻灯片### H3→ 带标题的内容幻灯片---→ 滑动分离器(如果slide_breaks: hr)
主题
# Light theme (default)
md-convert slides.md --format pptx --theme light
# Dark theme
md-convert slides.md --format pptx --theme dark
验证
已验证的内容
YAML前件:
- 有效的YAML语法
- 必填字段(格式、标题)
- 有效枚举值(格式、状态、document_type)
- 日期格式(推荐YYYY-MM-DD)
内容结构:
- 标题层次结构(无跳过级别:H1→ H2 → H3)
- 空标题
- 表列一致性
- 孤儿名单
元数据完整性:
- 如果缺少推荐字段(作者、日期、分类、版本、关键字),则发出警告
- 如果描述超过250个字符,则发出警告
验证模式
标准(默认):
md-convert document.md --format docx
- 以黄色显示警告
- 继续转换
- 建议大部分使用
严格模式:
md-convert document.md --format docx --strict
- 将警告视为错误
- 在任何警告下转换失败
- 用于生产/客户文件
无验证:
md-convert document.md --format docx --no-validate
- 跳过所有验证
- 更快地处理受信任的文档
- 不建议用于客户交付成果
完整的前件示例
---
# Required fields
format: docx # Output format
title: "Executive Brief - AI Strategy" # Document title
# Extended metadata (recommended)
author: "Dale Rogers" # Author name
date: "2025-11-10" # Date (YYYY-MM-DD)
classification: "OFFICIAL" # Security level
version: "1.0" # Version number
status: final # draft|review|approved|final
description: "Executive decision brief" # Brief description
keywords: ["AI", "strategy", "executive"] # Search keywords
subject: "Executive Briefing" # Category
# Document control (optional)
convert: true # Enable conversion (default)
document_type: document # document|email|reference|note|system
# Format-specific (optional)
section_breaks: auto # auto|all|none (DOCX)
slide_breaks: h2 # h1|h2|hr (PPTX)
---
# Your Document Starts Here
Content goes here...
请参阅: FRONTMATTER.md 完整规格
公式语法
基本用法
| Item | Amount | Tax | Total |
|------|--------|-----|-------|
| Product A | 100 | {=B2*0.1} | {=B2+C2} |
| Product B | 200 | {=B3*0.1} | {=B3+C3} |
| **Total** | {=SUM(B2:B3)} | {=SUM(C2:C3)} | {=SUM(D2:D3)} |
支持的功能
数学: 总和、平均值、计数、最小值、最大值、四舍五入、绝对值、平方分数、功率、模值、乘积
逻辑: IF,AND,OR,XOR,iferor,IFNA
文本: 连接,CONCAT,左,右,中,LEN,TRIM,上,下
日期: TODAY,NOW,DATE,YEAR,MONTH,DAY,week DAY,DATEDIF,DAYS
查找: VLOOKUP、HLOOKUP、XLOOKUP、索引、匹配、选择
统计: STDEV、VAR、排名、百分位数
财务: PMT、FV、PV、RATE、NPV、IRR
单元格引用
{=A1} # Simple reference
{=$A$1} # Absolute reference
{=A1:A10} # Range
{=B:B} # Entire column
{=1:10} # Row range
最佳实践
咨询交付成果
-
始终添加YAML前端内容
- 提供专业元数据
- 启用格式检测
- 显示文档所有权和版本
-
使用
section_breaks: autoDOCX- 洁净断面结构
- 主要部门获得独立
- 避免过度分割
-
设置适当的分类
- 官方、受保护等。
- 在文档属性中显示
- 对政府/企业重要
-
包括版本和状态
- 跟踪文档成熟度
status: draft对于正在进行的工作status: final用于客户交付
-
使用关键字进行搜索
- 每份文档3-6个关键字
- 帮助客户稍后查找文档
- 适用于文档管理系统
用于多格式输出
战略文件 → 仅限DOCX
format: docx
财务模型 → 仅限XLSX(用于配方奶粉)
format: xlsx
高管演讲 → DOCX+PPTX
format: docx,pptx
全面交付成果 → 所有格式
format: all
项目组织
交付物 → format: docx, status: final
参考文献 → document_type: reference (自动排除)
工作记录 → In /notes/ 目录(自动排除)
系统文档 → convert: false 或 document_type: system
例子
执行摘要
---
format: docx
title: "Executive Brief – Digital Transformation Strategy"
author: "Jane Smith"
date: "2025-11-10"
classification: "CONFIDENTIAL"
version: "1.0"
status: final
description: "Executive decision brief presenting strategic recommendations"
keywords: ["strategy", "digital transformation", "executive brief"]
subject: "Executive Briefing"
section_breaks: auto
---
# Executive Brief
## Situation
...
财务模型
---
format: xlsx
title: "Project Budget Model"
author: "John Doe"
date: "2025-11-10"
classification: "CONFIDENTIAL"
version: "1.0"
status: final
description: "Budget model with detailed cost breakdown and forecasts"
keywords: ["budget", "costing", "financial model", "forecast"]
subject: "Financial Planning"
---
# Budget Model
## Phase 1 Costs
| Item | Cost |
|------|------|
| Labour | {=SUM(B2:B10)} |
| Infrastructure | $50,000 |
| **Total** | {=SUM(B2:B11)} |
参考资料
---
format: docx
title: "Background Research"
author: "Team"
date: "2025-11-07"
classification: "OFFICIAL"
version: "0.5"
status: draft
document_type: reference # Auto-excluded from batch conversion
description: "Background research and analysis"
keywords: ["research", "background"]
subject: "Reference"
---
验证参考
常见错误(转换失败)
❌ 缺少必填字段: format 或 title
❌ 格式值无效
❌ 标题层次结构违规(H1→ H3,跳过H2)
❌ 空标题
❌ 表列计数不匹配
常见警告(继续警告)
⚠️ 缺少推荐字段(作者、日期、版本)
⚠️ 日期不是YYYY-MM-DD格式
⚠️ 描述>250个字符
⚠️ 文档中没有H1标题
⚠️ 没有语言标记的代码块
⚠️ 空列表
查看验证输出
Converting: document.md
⚠ Warnings:
• Recommended field missing: author
• Recommended field missing: version
📄 Executive Brief (docx)
v1.0 - final
✓ DOCX: document.docx
发展
# Install dependencies
npm install
# Build
npm run build
# Run CLI in dev mode (with TypeScript)
npm run dev -- input.md --format docx
# Start MCP server in dev mode
npm run serve
# Type check (without building)
npm run type-check
# Watch mode (auto-rebuild on changes)
tsc --watch
项目结构
md_converter/
├── src/
│ ├── core/
│ │ ├── parsers/
│ │ │ ├── markdown.ts # Markdown parsing
│ │ │ ├── frontmatter-parser.ts # YAML front matter
│ │ │ ├── table-parser.ts # Table processing
│ │ │ └── formula-parser.ts # Formula validation
│ │ ├── converters/
│ │ │ ├── docx-converter.ts # Word generation
│ │ │ ├── xlsx-converter.ts # Excel generation
│ │ │ ├── pptx-converter.ts # PowerPoint generation
│ │ │ └── section-rules.ts # Section/slide break logic
│ │ └── validators/
│ │ └── document-validator.ts # Document validation
│ ├── mcp/
│ │ ├── server.ts # MCP server
│ │ └── tools.ts # MCP tool definitions
│ ├── cli/
│ │ └── index.ts # CLI interface
│ └── index.ts # Main exports
├── examples/
│ ├── frontmatter-template.md # Template for new docs
│ ├── sample.md # Formula example
│ └── presentation.md # Presentation example
├── FRONTMATTER.md # Complete specification
├── CHANGELOG.md # Version history
├── README.md # This file
├── package.json # Dependencies
└── tsconfig.json # TypeScript config
技术细节
Markdown解析: markdown-it -基于AST的强大解析
DOCX生成: docx 库-专业Word文档,包括:
- 内置单词样式(普通、标题1-6、列表段落、强、强调)
- 列表的正确编号配置
- 独立格式化的部门管理
- 文档属性(标题、作者、主题、关键字、分类)
XLSX代: exceljs -Excel工作簿,包含:
- 原生公式支持(实际Excel公式,而非文本)
- 富格文本格式(单元格中粗体、斜体)
- 多个工作表(每个标记表一个)
- 自动调整列的宽度和冻结的标题
- 文档属性
PPTX代: pptxgenjs -PowerPoint演示文稿,包括:
- 灵活的幻灯片布局
- 主题支持(亮/暗)
- 表格和要点
- 文档属性
YAML解析: js-yaml -行业标准的YAML解析器
MCP集成: @modelcontextprotocol/sdk -官方模型上下文协议SDK
局限性
按格式支持公式
| 格式 | 公式支持 | 说明 |
|---|---|---|
| XLSX 文件 | ✅ 全力支持 | 公式转换为自动计算的实际Excel公式 |
| 文档 | ❌ 纯文本 | 以纯文本显示的公式(Word不支持单元格计算) |
| 演示文稿 | ❌ 纯文本 | 公式在表单元格中以纯文本显示 |
重要提示: 对于工作公式,请始终使用 format: xlsx.
其他限制
- 图像: 尚未支持(计划用于v2.2)
- 复杂嵌套列表: 仅限于单层列表
- 非常大的桌子: 可能需要在PPTX中手动调整
- 自定义Word模板: 尚不支持(仅使用内置样式)
- 美人鱼图: 不支持(呈现为代码块)
故障排除
“未找到表”错误
解决方案: XLSX格式需要标记表。在文档中至少添加一个表。
Excel中未显示粗体文本
解决方案: 使用v2.1.0或更高版本。早期版本有一个富文本格式错误(现已修复)。
编号列表在Word中不起作用
解决方案: 使用v2.1.0或更高版本。早期版本缺少编号配置(现已修复)。
Word中到处都有分节符
解决方案: 使用 section_breaks: auto 而不是 section_breaks: all自动模式仅在主要边界(##H2之前)创建部分。
转换过程中跳过的文件
解决方案: 检查文件是否符合排除规则:
- 是README.md吗?
- 它在/notes/或/references/目录中吗?
- 前件有没有
convert: false? - 前件有没有
document_type: email|reference|note|system?
贡献
这是一个活跃的项目。欢迎投稿!
贡献领域:
- 图像支持
- 自定义Word模板
- 多级列表支持
- 美人鱼图渲染
- 附加公式函数
- 增强的验证规则
更新日志
看 CHANGELOG.md 版本历史。
许可证
麻省理工学院
作者
戴尔·罗杰斯
服务设计负责人
2025
致谢
专为现实世界的咨询需求而设计,通过在企业和政府咨询项目中的生产使用进行改进。
开发用于支持 IDE优先咨询方法,使顾问能够利用人工智能的帮助,同时保持专业的客户交付成果。
注: 本项目全程使用澳大利亚英语拼写和日期格式(DD/MM/YYYY)。
