Skip to content

Commit ae187d2

Browse files
committed
Fix #32 for let format and lint get same result for Markdown Table.
1 parent 6ede510 commit ae187d2

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

autocorrect-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT"
77
name = "autocorrect-cli"
88
readme = "../README.md"
99
repository = "https://github.com/huacnlee/autocorrect"
10-
version = "1.5.9"
10+
version = "1.5.11"
1111

1212
[[bin]]
1313
name = "autocorrect"

autocorrect/grammar/markdown.pest

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
para = { ANY* ~ NEWLINE{2} }
2-
expr = { img | link | mark | heading }
2+
expr = { img | link | td_tag | mark | heading }
33
text = { (!(expr | NEWLINE) ~ ANY)+ }
44
space = @{ (" ")* }
55
code = ${
@@ -8,6 +8,7 @@ code = ${
88
code_block_lang = { ASCII_ALPHA* }
99
code_block_value = { (!(PEEK) ~ ANY)* }
1010
code_inline_value = { (!(PEEK | NEWLINE) ~ ANY)* }
11+
td_tag = @{ space ~ "|" ~ space }
1112
mark_tag = @{
1213
"**"
1314
| "*"

autocorrect/src/code/code.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn format_or_lint<R: RuleType, O: Results>(results: &mut O, rule_name: &str,
8181
// format trimmed string
8282
let new_line = format(line_str);
8383

84-
// nothing changed, skip
84+
// skip, when no difference
8585
if new_line.eq(line_str) {
8686
sub_line += 1;
8787
continue;
@@ -118,11 +118,7 @@ pub fn format_or_lint<R: RuleType, O: Results>(results: &mut O, rule_name: &str,
118118
if results.is_enabled() {
119119
let lines = part.split('\n');
120120

121-
new_part = lines
122-
.into_iter()
123-
.map(|line_str| format(line_str))
124-
.collect::<Vec<_>>()
125-
.join("\n");
121+
new_part = lines.into_iter().map(format).collect::<Vec<_>>().join("\n");
126122
}
127123

128124
results.push(LineResult {

autocorrect/src/code/markdown.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ mod tests {
3434
// Codeblock里面也会处理
3535
let a = "你好hello";
3636
```
37+
38+
| 字段 | 长度(bit) | 长度(字节)| 说明 |
39+
| ---------- | ---------- | ------------ | -------------------------------------------------------------------------- |
40+
| request_id | 32(uint32) | 4 | 请求id,同一个连接的id需要唯一,从1开始,到达4294967295后从新开始。 |
41+
| timeout | 16(uint16) | 2 | `timeout` 单位毫秒,最大60000(60s) |
3742
3843
- ![img图片](https://google.com/a/b/url不处理)
3944
- [link链接](https://google.com/a/b/url不处理)
@@ -57,11 +62,22 @@ mod tests {
5762
// Codeblock 里面也会处理
5863
let a = "你好 hello";
5964
```
65+
66+
| 字段 | 长度 (bit) | 长度(字节)| 说明 |
67+
| ---------- | ---------- | ------------ | -------------------------------------------------------------------------- |
68+
| request_id | 32(uint32) | 4 | 请求 id,同一个连接的 id 需要唯一,从 1 开始,到达 4294967295 后从新开始。 |
69+
| timeout | 16(uint16) | 2 | `timeout` 单位毫秒,最大 60000(60s) |
6070
6171
- ![img 图片](https://google.com/a/b/url不处理)
6272
- [link 链接](https://google.com/a/b/url不处理)
6373
"###;
6474

65-
assert_eq!(expected, format_markdown(example).to_string())
75+
assert_eq!(expected, format_markdown(example).to_string());
76+
77+
let lint_result = lint_markdown(expected);
78+
assert_eq!(false, lint_result.has_error());
79+
if !lint_result.lines.is_empty() {
80+
panic!("{}", lint_result.to_string());
81+
}
6682
}
6783
}

0 commit comments

Comments
 (0)