# md2excel **Repository Path**: liudc0810/md2excel ## Basic Information - **Project Name**: md2excel - **Description**: md等格式转换成excel等,go语言编写。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-19 - **Last Updated**: 2026-06-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # md2excel v1.0.1 — 多格式表格转换工具 从 Markdown、HTML、CSV 文件中提取表格,输出为 Excel、CSV 或 JSON。 ## 安装 ```bash git clone cd md2excel go build -o md2excel.exe . ``` ## 快速开始 ```bash md2excel -input README.md # Markdown → Excel md2excel -input page.html -of csv # HTML → CSV md2excel -input data.csv -of json # CSV → JSON ``` ## 使用示例 ### 基本转换 ```bash md2excel -input data.md # 自动检测输出格式 md2excel -input data.md -of excel # 指定输出 Excel md2excel -input data.md -of csv # 指定输出 CSV md2excel -input data.md -of json # 指定输出 JSON ``` ### 批量转换 ```bash md2excel -input *.md # 批量处理 md2excel -input docs/*.md -of csv # 批量转 CSV md2excel -input data/*.html -of json -j 4 # 4 并发处理 ``` ### stdin/stdout 管道 ```bash echo '|A|B|\\n|1|2|' | md2excel -input - -of json # stdin → stdout cat data.csv | md2excel -input - -if csv -of json # 管道处理 md2excel -input data.md -of csv -output - # 输出到 stdout ``` ### 数据处理 ```bash md2excel -input data.md -of excel -sheet "汇总" # 自定义工作表名 md2excel -input data.md -of excel -all-in-one # 合并所有表格 md2excel -input data.md -of excel -disable-num-detect # 禁用数字检测 md2excel -input data.md -of excel -transform filter,sort,dedup # 应用变换 md2excel -input data.md -of excel -transform "sort:1:desc" # 按第2列降序排序 md2excel -input data.md -of excel -transform "dedup:0" # 按第1列去重 ``` ### 查看信息 ```bash md2excel -version # 显示版本 md2excel -list-plugins # 列出所有插件 md2excel -help # 帮助信息 md2excel -input data.md -of excel -q # 静默模式(不显示进度) ``` ## 命令行参数 | 参数 | 说明 | 默认值 | |------|------|--------| | `-input ` | 输入文件路径(支持通配符 `*.md`;`-` 表示 stdin) | 必填 | | `-output ` | 输出文件路径(`-` 表示 stdout) | 自动 | | `-if ` | 输入格式:markdown, html, csv | 自动检测 | | `-of ` | 输出格式:excel, csv, json | 自动检测 | | `-sheet ` | 自定义工作表名(仅 Excel) | Sheet1 | | `-all-in-one` | 所有表格合并到同一工作表 | false | | `-disable-num-detect` | 禁用数字自动检测 | false | | `-transform ` | 应用的变换插件(支持参数如 `sort:1:desc,dedup:0`) | normalize | | `-j ` | 并发处理数(0=CPU核心数) | 1 | | `-version` | 显示版本信息 | - | | `-list-plugins` | 列出所有可用插件 | - | | `-q` | 静默模式(不显示进度) | false | ## 格式支持 ### 输入格式 | 格式 | 扩展名 | 说明 | |------|--------|------| | Markdown | `.md`, `.markdown` | 优先 goldmark AST 解析,降级行解析 | | HTML | `.html`, `.htm` | XPath 提取 `` 元素 | | CSV | `.csv`, `.tsv` | 自动检测逗号/制表符分隔 | ### 输出格式 | 格式 | 扩展名 | 说明 | |------|--------|------| | Excel | `.xlsx` | 多 Sheet,智能列宽,样式美化 | | CSV | `.csv` | UTF-8 BOM 兼容 Excel | | JSON | `.json` | 格式化输出,含 headers/rows | ## 插件架构 md2excel 采用插件化设计,易于扩展: ``` ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ InputPlugin │───▶│ Pipeline │───▶│OutputPlugin │ └─────────────┘ └─────────────┘ └─────────────┘ │ ┌─────┴─────┐ │Transform │ │Plugin │ └───────────┘ ``` ### 已注册插件 **输入插件 (3)** - `markdown` — Markdown 表格提取 - `html` — HTML 表格提取 - `csv` — CSV/TSV 解析 **输出插件 (3)** - `excel` — Excel 文件生成 - `csv` — CSV 文件生成 - `json` — JSON 文件生成 **变换插件 (5)** - `normalize` — 列数统一 - `filter` — 过滤空行 - `sort` — 按列排序 - `dedup` — 去除重复行 - `merge` — 合并多个表格 ### 扩展插件 实现相应接口即可添加新插件: ```go // 输入插件 type InputPlugin interface { Name() string Extensions() []string Parse(data []byte) ([]TableData, error) } // 输出插件 type OutputPlugin interface { Name() string Extension() string Write(tables []TableData, path string, opts OutputOptions) error } // 变换插件 type TransformPlugin interface { Name() string Transform(tables []TableData) ([]TableData, error) } ``` ## 特性 | 特性 | 说明 | |------|------| | 插件架构 | 输入/输出/变换三类插件,Registry + Pipeline 模式 | | 多格式支持 | 3 种输入格式 × 3 种输出格式 = 9 种组合 | | 双引擎解析 | goldmark AST 精确解析,失败自动降级行解析;支持行内代码(`code`) | | 数据标准化 | 自动去除空白、统一列数、数字识别 | | 智能列宽 | Excel 输出自动调整列宽 | | 批量处理 | 支持通配符和并发(`-j`) | | 管道支持 | stdin/stdout,可与其他工具组合 | | 彩色输出 | 终端友好,自动检测是否为 TTY | ## 项目结构 ``` md2excel/ ├── main.go # CLI 入口 ├── pkg/ │ ├── plugin/ # 插件接口和管道 │ │ ├── types.go # 接口定义 │ │ ├── registry.go # 插件注册表 │ │ └── pipeline.go # 执行管道 │ ├── input/ # 输入插件 │ │ ├── markdown.go # Markdown 解析 │ │ ├── html.go # HTML 解析 │ │ └── csv.go # CSV/TSV 解析 │ ├── output/ # 输出插件 │ │ ├── excel.go # Excel 写入 │ │ ├── csv.go # CSV 写入 │ │ └── json.go # JSON 写入 │ ├── transform/ # 变换插件 │ │ ├── normalize.go # 列数统一 │ │ ├── filter.go # 行过滤 │ │ ├── sort.go # 行排序 │ │ ├── dedup.go # 去重 │ │ └── merge.go # 合并表格 │ └── term/ # 终端输出 │ ├── colors.go # ANSI 颜色 │ └── progress.go # 进度指示 ``` ## 测试 ```bash go test -v ./... # 运行所有测试 go test -v -run TestName # 运行指定测试 ``` ## 更新日志 ### v1.0.1 (2026-06-21) - 修复 Markdown 表格中行内代码(`code`)解析 panic 问题 - 新增 `TestMarkdownInput_CodeSpan` 测试用例 - 新增 `md2excel` skill(`~/.mimocode/skills/md2excel/SKILL.md`) ### v1.0.0 (2026-06-20) - 插件化架构:Input/Output/Transform 三类插件 - 支持 Markdown、HTML、CSV 输入;Excel、CSV、JSON 输出 - 双引擎解析:goldmark AST + 行解析降级 - 批量处理、管道支持、智能列宽 ## 许可证 MIT