markdown 文档格式检查工具 lint-md

2018-11-23 15:37:40 +08:00
 50vip

lint-md

用于检查中文 markdown 编写格式规范的命令行工具,基于 AST 开发,且方便集成 ci。Cli tool to lint your markdown file for Chinese.

开源地址:https://github.com/hustcc/lint-md

安装

npm i -g lint-md

使用

Usage: <lint-md> <files...> [options]

lint your markdown files

Options:
  -v, --version                  output the version number
  -c, --config [configure-file]  use the configure file, default .lintmdrc
  -h, --help                     output usage information

Example:

lint-md README.md Document.md

检查类型

检查规则来源于 chinese-copywriting-guidelines.

| 规则 | 详细描述 | 解决办法 | | ------ | ------ | ------ | | space-between | 中文与英文数字之间需要增加空格 | 响应位置增加空格 | | no-empty-code-lang | 代码语言不能为空 | 在代码块语法上增加语言 | | no-empty-url | 链接和图片地址不能为空 | 填写完整的 url,或者不使用链接和图片语法 | | no-empty-list | List 内容不能为空 | List 语法中,填写内容 | | no-empty-code | 代码块内容不能为空 | 删除空的代码块,或者填充代码内容 | | no-empty-blockquote | blockquote 内容不能为空 | 删除空的 blockquote,或者填充内容 | | no-special-characters | 文本中不能有特殊字符 | 可能是复制出来的特殊字符,删除特殊字符即可 |

目前仅仅检查了比较通用的类型,欢迎 pull request,在 rules 中增加自己的规则,开发约束:

配置

默认所有的规则都是 error 类型,但是可以通过配置来指定规则类型。示例 .lintmdrc

{
  "excludeFiles": [],
  "rules": {
    "no-empty-code": 1
  }
}

通过 rules 来配置规则的等级。

通过 excludeFiles 来忽略文件和目录,glob 语法。

ci 集成

.travis.yml 文件中配置以下内容。

language: node_js
node_js:
  - "10"
before_install:
  - npm i -g lint-md
script: lint-md README.md

package.json 中增加以下配置。

"lint-staged": {
  "src/**/*.{md,markdown}": [
    "lind-md"
  ]
}

License

MIT@hustcc.

4211 次点击
所在节点    分享创造
9 条回复
Showfom
2018-11-23 16:03:04 +08:00
支持一下
lonelinsky
2018-11-23 16:18:49 +08:00
目前在用 VSCode 的 markdownlint,表示很好用,支持。
50vip
2018-11-23 16:48:58 +08:00
@lonelinsky 我是希望多加一些中文的格式校验,所以做了 lint-md,用于写文章,写博客,优化排版!
50vip
2018-11-23 16:54:50 +08:00
@lonelinsky 这个的好处就是可以在 ci 中使用,这样大家 pr 的时候,都可以按照这么标准来!
lonelinsky
2018-11-23 16:55:28 +08:00
@50vip #3 是指「中文文案排版指北」这样的排版规范吗?我当时用它里面提供的排版工具排版了下我的博客,然后因为 Hexo 的一些特殊要求,导致博客直接崩了,后来又重新手动修正了下 =。=
50vip
2018-11-23 17:01:06 +08:00
@lonelinsky 那个里面我只是采用了 中文和英文数字之间要有空格 这一条。

他那个脚本好像用正则匹配,肯定容易崩!
chungzhao
2018-11-24 15:50:39 +08:00
真棒!!!
chungzhao
2018-11-24 16:01:21 +08:00
可以批量检测吗?
50vip
2018-11-26 09:48:49 +08:00
@chungzhao 可以批量检查格式就是往后面无限加就可以了!

lint-md xx.md yy.md doc

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/510815

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX