Skip to content

Commit ae9389d

Browse files
committed
docs: add new option and update docs runtime
1 parent 26c46cf commit ae9389d

File tree

6 files changed

+4550
-9412
lines changed

6 files changed

+4550
-9412
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ If you want to ignore the whole file, you can also add this HTML comment:
284284

285285
*... and this part might be controversial. So if you don't feel well at some point, we definitely would love to know and improve. Opening an [issue](https://github.com/zhlint-project/zhlint/issues) is always welcome. Then we could discuss about the possible better option or decision.*
286286

287-
```ts
287+
````ts
288288
type RuleOptions = {
289289
/* PRESET */
290290

@@ -404,7 +404,7 @@ type RuleOptions = {
404404
// e.g. `文字, 文字` -> `文字,文字`
405405
noSpaceAfterFullwidthPauseOrStop?: boolean
406406

407-
/* SPACES AROUND QUOTES */
407+
/* SPACES AROUND QUOTATIONS */
408408

409409
// default preset: `true`
410410
// - `true`: one space
@@ -467,8 +467,13 @@ type RuleOptions = {
467467
// default `true`
468468
// e.g. ` 文字 ` -> `文字`
469469
trimSpace?: boolean
470+
471+
/* SKIP PURE WESTERN SENTENCES */
472+
473+
// default `true`
474+
skipPureWestern?: boolean
470475
}
471-
```
476+
````
472477

473478
## More information
474479

README.zh-CN.md

+107-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,48 @@ zhlint --help
4040

4141
![](./docs/screenshot-cli.png)
4242

43+
#### Advanced usage
44+
45+
zhlint also supports rc and ignore config files for custom rules:
46+
47+
```bash
48+
# .zhlintrc by default
49+
zhlint --config <filepath>
50+
51+
# .zhlintignore by default
52+
zhlint --ignore <filepath>
53+
zhlint --file-ignore <filepath>
54+
55+
# .zhlintcaseignore by default
56+
zhlint --case-ignore <filepath>
57+
58+
# current directory by default
59+
zhlint --dir <path>
60+
```
61+
62+
In the config file, you can write a JSON like:
63+
64+
```json
65+
{
66+
"preset": "default",
67+
"rules": {
68+
"adjustedFullWidthPunctuation": ""
69+
}
70+
}
71+
```
72+
73+
For more details, see [supported rules](#supported-rules).
74+
75+
In the file-ignore file, you can write some lines to ignore files in [.gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format):
76+
77+
In the case-ignore file, you can write some lines of ignored cases like:
78+
79+
```txt
80+
( , )
81+
```
82+
83+
For more details, see [setup ignored cases](#setup-ignored-cases).
84+
4385
### 作为 Node.js 包
4486

4587
```js
@@ -74,6 +116,26 @@ Invalid files:
74116
Found 2 errors.
75117
```
76118

119+
#### Advanced usage
120+
121+
zhlint also supports rc and ignore config files for custom rules:
122+
123+
```js
124+
const { readRc, runWithConfig } = require('zhlint')
125+
126+
const value = '自动在中文和English之间加入空格'
127+
128+
const dir = '...' // the target directory path
129+
const configPath = '...' // the config file path
130+
const fileIgnorePath = '...' // the file-ignore file path
131+
const caseIgnorePath = '...' // the case-ignore file path
132+
133+
const config = readRc(dir, configPath, fileIgnorePath, caseIgnorePath)
134+
const output = runWithConfig(value, config)
135+
136+
// ... further actions
137+
```
138+
77139
### 作为一个单独的包
78140

79141
您可以找到一个 JavaScript 文件 `dist/zhlint.js` 作为独立版本。 例如,要使用它,您可以直接将它添加到您的浏览器中作为 `<script>` 标签。 即可访问全局变量 `zhlint`
@@ -92,6 +154,8 @@ Found 2 errors.
92154
- 参数:
93155
- `results`:所有格式化结果的数组。
94156
- `logger`:日志处理器实例,默认是 Node.js/浏览器中的 `console`
157+
- `readRc: (dir: string, config: string, ignore: string, logger?: Console) => Config`: Read config from rc file(s). For rc (run command).
158+
- `runWithConfig(str: string, config: Config): Result`: Lint a certain file with rc config. For rc (run command).
95159

96160
### 选项
97161

@@ -113,20 +177,32 @@ type Options = {
113177
- 遵循该特定的格式,灵感来自 [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment)。
114178
- `logger`:和 `report(...)` 中的参数相同。
115179
180+
### RC Config
181+
182+
- `preset`: `string` (optional)
183+
- `rules`: `RuleOptions` without the `preset` field. (optional)
184+
- `hyperParsers`: `string[]` (optional)
185+
- `caseIgnores`: `string[]` and the priority is lower than `.zhlintcaseignore`. (optional)
186+
116187
### 输出格式
117188
118189
```ts
119190
type Result = {
191+
// the basic info and availability of the file
120192
file?: string
193+
disabled: boolean
194+
195+
// the original content of the file
121196
origin: string
122-
result: string
197+
198+
// all the error messages
123199
validations: Validation[]
124200
}
125201

126202
type Validation = {
203+
message: string
127204
index: number
128205
length: number
129-
message: string
130206
}
131207
```
132208
@@ -140,23 +216,33 @@ type Validation = {
140216
- `length`:输入的字符串中目标片段的长度。
141217
- `message`:对该校验信息的自然语言描述。
142218
219+
### Advanced usage
220+
143221
## 特性
144222
145223
### Markdown 语法支持
146224
225+
We support lint your text content in Markdown syntax by default. For example:
226+
147227
```js
148228
run('自动在_中文_和**English**之间加入空格')
149229
```
150230
231+
It will analyse the Markdown syntax first and extract the pure text content and do the lint job. After that the fixed pure text content could be replaced back to the raw Markdown string and returned as the output `value` in result.
232+
151233
### [Hexo tag](https://hexo.io/docs/tag-plugins) 语法支持
152234
235+
Specially, we support [Hexo tags syntax](https://hexo.io/docs/tag-plugins) just because when we use Hexo to build Vue.js website, the markdown source files more or less include special tags like that so got the unpredictable result.
236+
237+
As a result, we additionally skip the Hexo-style tags by default. For example:
238+
153239
```js
154240
run('现在过滤器只能用在插入文本中 (`{% raw %}{{ }}{% endraw %}` tags)。')
155241
```
156242
157243
### 设置被忽略的特例
158244
159-
通过 HTML 注释:
245+
In some real cases we have special text contents not follow the rules by reason. So we could ues `ignoredCases` option to config that. For example we'd like to keep the spaces inside a pair of brackets, which is invalid by default. Then we could write one more line of HTML comment anywhere inside the file:
160246
161247
```md
162248
<!-- the good case -->
@@ -177,6 +263,12 @@ vm.$on( event, callback )
177263
run(str, { ignoredCases: { textStart: '( ', textEnd: ' )' } })
178264
```
179265

266+
If you want to ignore the whole file, you can also add this HTML comment:
267+
268+
```md
269+
<!-- zhlint disabled -->
270+
```
271+
180272
## 支持的预处理器 (超文本解析器)
181273

182274
- `ignore`:通过 HTML 注释 `<!-- zhlint ignore: ... -->` 匹配所有被忽略的特例
@@ -189,7 +281,7 @@ _大多数规则都提炼自过往 [W3C 中文排版需求](https://www.w3.org/I
189281

190282
_……这些规则也许存在争议。所以如果你对某些规则不够满意,我们非常希望得到大家的反馈和改进建议。我们也一直欢迎大家来创建 [issue](https://github.com/zhlint-project/zhlint/issues),以讨论出可能更好的规则。_
191283

192-
```ts
284+
````ts
193285
type RuleOptions = {
194286
/* PRESET */
195287

@@ -309,7 +401,7 @@ type RuleOptions = {
309401
// e.g. `文字, 文字` -> `文字,文字`
310402
noSpaceAfterFullwidthPauseOrStop?: boolean
311403

312-
/* SPACES AROUND QUOTES */
404+
/* SPACES AROUND QUOTATIONS */
313405

314406
// default preset: `true`
315407
// - `true`: one space
@@ -372,5 +464,14 @@ type RuleOptions = {
372464
// default `true`
373465
// e.g. ` 文字 ` -> `文字`
374466
trimSpace?: boolean
467+
468+
/* SKIP PURE WESTERN SENTENCES */
469+
470+
// default `true`
471+
skipPureWestern?: boolean
375472
}
376-
```
473+
````
474+
475+
## More information
476+
477+
zhlint is now open sourced on [GitHub](https://github.com/zhlint-project/zhlint) and [issues](https://github.com/zhlint-project/zhlint/issues) welcome.

docs/index.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ If you want to ignore the whole file, you can also add this HTML comment:
294294

295295
_Almost the rules come from the past translation experiences in [W3C Requirements for Chinese Text Layout](https://www.w3.org/International/clreq/), [W3C HTML Chinese interest group](https://www.w3.org/html/ig/zh/wiki/Main_Page) and [Vue.js Chinese docsite](https://github.com/vuejs/cn.vuejs.org/wiki)._
296296

297-
_... and this part might be controversial. So if you don't feel well at some point, we definitely would love to know and improve. Opening an [issue](https://github.com/zhling-project/zhlint/issues) is always welcome. Then we could discuss about the possible better option or decision._
297+
_... and this part might be controversial. So if you don't feel well at some point, we definitely would love to know and improve. Opening an [issue](https://github.com/zhlint-project/zhlint/issues) is always welcome. Then we could discuss about the possible better option or decision._
298298

299-
```ts
299+
````ts
300300
type RuleOptions = {
301301
/* PRESET */
302302

@@ -416,7 +416,7 @@ type RuleOptions = {
416416
// e.g. `文字, 文字` -> `文字,文字`
417417
noSpaceAfterFullwidthPauseOrStop?: boolean
418418

419-
/* SPACES AROUND QUOTES */
419+
/* SPACES AROUND QUOTATIONS */
420420

421421
// default preset: `true`
422422
// - `true`: one space
@@ -479,8 +479,13 @@ type RuleOptions = {
479479
// default `true`
480480
// e.g. ` 文字 ` -> `文字`
481481
trimSpace?: boolean
482+
483+
/* SKIP PURE WESTERN SENTENCES */
484+
485+
// default `true`
486+
skipPureWestern?: boolean
482487
}
483-
```
488+
````
484489

485490
## More information
486491

0 commit comments

Comments
 (0)