中文排版校对工具:检查并自动修复中英文间距、全角标点、术语统一等问题,提供命令行工具与可复用库。
Dependencies
$ mbt-typeset --markdown 文档.md
文档.md:3:5: warning [cjk-latin-space] 中文与英文或数字之间应插入一个空格 (可自动修复)
文档.md:3:14: warning [fullwidth-punct] 中文语境中应使用全角标点「,」 (可自动修复)
文档.md:3:24: warning [ellipsis] 省略号应使用中文省略号「……」 (可自动修复)$ mbt-typeset --markdown --fix 文档.md
文档.md: 已应用 34 处修复,剩余 0 处问题修复前:本文使用MoonBit编写,演示常见的排版问题... 修复后:本文使用 MoonBit 编写,演示常见的排版问题……
| 方向 | 生态现状 |
|---|---|
| Markdown 解析 / 渲染 | 已有 mizchi/markdown、moon-ssg 等 |
| JSON Schema / 校验 | 已有 mizchi/jsonschema、Betterlol/moon_zod |
| CSV / SQL / 数据库 | 已有 maria/csv_parser、uiwcvb/moonsql、sqlparser |
| 序列化 / 网络协议 | 已有 mizchi/cbor、hackwaly/msgpack、http11、moonbit-mqtt |
| 拼音 / 分词 / emoji | 已有 walkzzz/pinyin、colmugx/jieba、fundon/emoji |
| 中文排版校对 | 索引中不存在任何排版检查 / 校对类包 |
| 规则 id | 默认 | 可修复 | 说明 |
|---|---|---|---|
| cjk-latin-space | 开 | 是 | 中文与英文、数字之间插入空格 |
| fullwidth-punct | 开 | 是 | 中文语境中的半角标点改为全角 |
| fullwidth-alnum | 开 | 是 | 中文语境中的全角字母数字改为半角 |
| curly-quote | 开 | 是 | 中文语境中的直引号改为弯引号 |
| quote-pairing | 开 | 否 | 引号必须成对出现 |
| duplicate-punct | 开 | 是 | 重复标点只保留一个 |
| ellipsis | 开 | 是 | 省略号统一为「……」 |
| dash | 开 | 是 | 中文破折号统一为「——」 |
| number-range | 开 | 是 | 数字区间号统一为半角 ~ |
| space-around-punct | 开 | 是 | 全角标点周围不应有多余空格 |
| number-unit-space | 开 | 是 | 数字与单位之间插入空格 |
| percent-sign | 开 | 是 | 百分号与数字之间不应有空格 |
| terminology | 开 | 是 | 术语大小写与写法统一(如 github → GitHub) |
| trailing-whitespace | 开 | 是 | 行尾不应有多余空白 |
| blank-line-collapse | 开 | 是 | 连续空行压缩为 1 个 |
| heading-space | 开 | 是 | Markdown 标题的 # 之后应有空格 |
| heading-level-jump | 开 | 否 | Markdown 标题层级不应跳跃 |
| heading-trailing-punct | 开 | 是 | 标题末尾不应有句读标点 |
| list-marker-space | 开 | 是 | Markdown 列表标记之后应有空格 |
| list-marker-consistency | 开 | 是 | 同文档内列表标记保持一致 |
| blockquote-space | 开 | 是 | Markdown 引用块的 > 之后应有空格 |
| table-separator | 开 | 否 | 表格分隔行列数与表头一致 |
| link-bare | 开 | 是 | 链接文字与地址相同时可简写为 <地址> |
| image-alt | 开 | 否 | Markdown 图片应提供 alt 文本 |
| inline-code-space | 开 | 是 | 行内代码与中文之间加空格 |
| emoji-space | 开 | 是 | emoji 与中文之间加空格 |
| unclosed-code-fence | 开 | 否 | Markdown 代码围栏未闭合(error 级) |
| halfwidth-punct-in-latin | 关 | 是 | 英文语境中的全角标点改为半角 |
| consecutive-spaces | 关 | 是 | 正文中不应出现连续空格 |
| line-length | 关 | 否 | 行宽上限检查(需设置 maxLineLength) |
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm https://cli.moonbitlang.cn/install/powershell.ps1 | iexcurl -fsSL https://cli.moonbitlang.cn/install/unix.sh | bashgit clone <this-repo>
cd mbt-typeset
moon check # 类型检查
moon build # 构建用法:
mbt-typeset [选项] <文件...>
选项:
--fix 就地修复可自动修复的问题
--format <text|json|github> 输出格式(默认 text)
--config <路径> 读取 JSON 配置
--markdown 按 Markdown 文档处理
--max-line-length <n> 行宽上限(0 表示不检查)
--rule <id=on|off> 启用/关闭某条规则(可重复)
--terminology <源=标准> 追加术语(可重复)
--list-rules 列出全部规则
-v, --version 显示版本
-h, --help 显示帮助
退出码:
0 未发现问题
1 发现 warning 及以上问题
2 用法错误或读写失败moon run cmd/main -- --markdown examples/before.md # 检查
moon run cmd/main -- --markdown --fix examples/after.md # 修复
moon run cmd/main -- --format json examples/before.md # JSON 输出
moon run cmd/main -- --list-rules # 规则表# 关闭术语规则,并开启「英文语境用半角标点」
moon run cmd/main -- --markdown \
--rule terminology=off \
--rule halfwidth-punct-in-latin=on \
examples/before.md{
"markdown": true,
"maxLineLength": 120,
"rules": {
"halfwidth-punct-in-latin": true,
"consecutive-spaces": false
},
"terminology": {
"moonbit": "MoonBit",
"javascript": "JavaScript"
}
}// 1. 检查:返回按位置排序的诊断列表
let diags = @lib.lint(source, @lib.Config::markdown())
// 2. 修复:返回修复结果、应用的编辑数与剩余问题
let outcome = @lib.fix(source, @lib.Config::markdown())
println(outcome.output) // 修复后的文本
println(outcome.applied) // 应用了多少处修复
println(outcome.remaining) // 仍然存在、但无法自动修复的问题
// 3. 渲染:text / json / github 三种输出
let report = @lib.render_text(diags, "文档.md")pub struct Diagnostic {
rule : String // 规则 id
severity : Severity // Error | Warning | Info
message : String // 说明
line : Int // 1 起始行号
column : Int // 1 起始列号(按字符计)
start : Int // 全文字符偏移(闭端,用于修复)
end : Int // 全文字符偏移(开端)
replacement : String? // 可自动修复时的替换文本
}moon testmoon run cmd/verify
# mbt-typeset 自检:共 69 条用例,失败 0 条
# 全部通过mbt-typeset/
├── charclass.mbt # Unicode 字符分类:CJK 文字 / CJK 标点 / 全角 / ASCII
├── types.mbt # Diagnostic、Severity、RuleInfo、FixOutcome
├── config.mbt # 运行配置与内置术语表
├── segment.mbt # 扫描:切行、识别代码区域、构造逐字符「保护掩码」
├── blocks.mbt # 块级分析:标题 / 列表 / 表格 / 缩进代码块
├── quotes.mbt # 引号配对状态机与中文弯引号转换
├── rules.mbt # 30 条规则 + 规则注册表
├── engine.mbt # lint / fix(迭代到不动点)+ 位置计算
├── render.mbt # text / json / github 渲染 + 规则表
├── conformance.mbt # 一致性语料 + 自检入口
├── mbt-typeset_test.mbt # 黑盒测试(只走公开 API)
├── cmd/main # 命令行工具
├── cmd/verify # 自检程序
├── examples/ # 前后对比示例、配置示例
└── PROJECT_PROPOSAL.md # 大赛项目申报书pub struct Block {
kind : BlockKind
start : Int
end : Int
line : Int
indent : Int
level : Int
marker : ListMarker?
columns : Int
} derive(Eq, Debug)pub struct FixOutcome {
output : String
applied : Int
remaining : Array[Diagnostic]
} derive(Eq, Debug)fn convert_straight_quotes(text : String) -> Stringfn fullwidth_alnum_to_ascii(c : Char) -> Char?fn is_cjk_ideograph(c : Char) -> Boolfn is_fullwidth_form(c : Char) -> Boolfn is_variation_selector(c : Char) -> BoolInstall
Download zip中文排版校对工具:检查并自动修复中英文间距、全角标点、术语统一等问题,提供命令行工具与可复用库。
Dependencies