開源:hint - 中文 Markdown 格式檢查,可以集成 Travis CI
hint
A simple markdown lint / hint cli-tool , for markdown developer integrated with travis.
一個簡單的 markdown 靜態檢查的控制臺 cli 工具,可以方便 markdown 開發者輕松集成 travis 自動檢測。
一、安裝
pip install hint
然后在系統中會得到一個 hint 的命令 cli 工具。
二、使用
使用方法有兩種:
2.1 一種是 命令行 cli 方式 ,簡單使用方法如下:
hint markdown_file
或者
hint markdown_folder
或者使用 hint --help 查看幫助信息和具體詳細的使用方法。
$ hint --help Usage: hint-script.py [OPTIONS] FILEOptions: -i, --ignore TEXT The error codes which will be ignored. -f, --format [text|json] The output format of error information. -m, --max-depth INTEGER The max depth for traverse the path. --help Show this message and exit.</pre>
可以用于直接集成到各種 ci 系統中,例如 travis-ci。
2.2 另外一種是 代碼 API 調用的方式 ,簡單使用方法如下:
import hinttext=''' hint 是一個簡單的 markdown 靜態檢查的控制臺
cli
工具。 可以方便 markdown 開發者輕松集成 travis 自動檢測。 ''' errors = hint.check(text, ignore='E201')fn = 'README.md' errors = hint.check_file(fn, format='text')</pre>
可以方便的進行第三方擴展開發。
三、錯誤碼
檢查規則來源于 chinese-copywriting-guidelines ,錯誤碼命名方式參考于 flake8。目前支持的錯誤碼如下所示:
錯誤碼 | 檢查類型 | 詳細描述 | 完成 |
---|---|---|---|
E101 | 空格 | 中英文之間需要增加空格 | done |
E102 | 空格 | 中文與數字之間需要增加空格 | done |
E103 | 空格 | 全角標點與其他字符之間不加空格 | done |
E104 | 空格 | 除了%、℃、°、以及倍數單位(如 2x、3n)之外,數字與單位之間需要增加空格 | done |
E201 | 標點 | 不重復使用標點符號 | done |
E202 | 標點 | 只有中文或中英文混排中,一律使用中文全角標點 | done |
E203 | 標點 | 如果出現整句英文,則在這句英文中使用英文、半角標點 | done |
E204 | 標點 | 省略號請使用……標準用法 | done |
E205 | 標點 | 英文和后面的半角標點之間不需要空格 | done |
E301 | 數字 | 數字使用半角字符 | done |
關于各種錯誤碼的正確、錯誤范例,可以參考 tests/md 。 目前有了大概的代碼結構,歡迎 PR 更多的檢查錯誤類型和檢查方式 。
LICENSE
MIT @ hustcc .