Skip to content

Commit e3b8d30

Browse files
committedApr 11, 2022
Fix #25 Markdown parser to identify Heading for avoid change # spaces.
1 parent a737be0 commit e3b8d30

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
 

‎autocorrect/grammar/markdown.pest

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
para = { ANY* ~ NEWLINE{2} }
2-
expr = { img | link | mark }
2+
expr = { img | link | mark | heading }
33
text = { (!(expr | NEWLINE) ~ ANY)+ }
4+
space = @{ (" ")* }
45
code = ${
56
PUSH("```") ~ code_block_lang ~ code_block_value ~ PUSH("```")
67
}
@@ -15,12 +16,15 @@ mark_tag = @{
1516
| "_"
1617
| "`"
1718
}
19+
heading_tag = @{"######" | "#####" | "####" | "###" | "##" | "#"}
20+
1821
img_start = @{ "!" }
1922
img = ${ img_start ~ link }
2023
link = ${ link_string ~ link_url }
2124
link_string = { "[" ~ (!("]" | NEWLINE) ~ ANY)* ~ "]" }
2225
link_url = { "(" ~ (!(")" | NEWLINE) ~ ANY)* ~ ")" }
2326
mark = ${ PUSH(mark_tag) ~ string ~ PUSH(mark_tag) }
27+
heading = ${ PUSH(heading_tag) ~ space ~ string }
2428
string = ${ (!(PEEK | NEWLINE) ~ ANY)* }
2529

2630
line = { expr | text | NEWLINE }

‎autocorrect/src/code/markdown.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ mod tests {
2323
*倾斜*
2424
~~删除线~~
2525
这是**Bold加粗**在1个段落中,这端会correct掉,如果是inline code,例如`Rust语言`,也可以应该处理。
26-
26+
27+
## (一)测试Heading处理,应该忽略#号后再处理.
28+
###测试Heading处理,应该忽略#号后再处理.
29+
#### 测试Heading处理,应该忽略#号后再处理!
30+
2731
> 引用文本:Quote也是可以的。
2832
2933
```rust
@@ -42,7 +46,11 @@ mod tests {
4246
*倾斜*
4347
~~删除线~~
4448
这是**Bold 加粗**在 1 个段落中,这端会 correct 掉,如果是 inline code,例如`Rust 语言`,也可以应该处理。
45-
49+
50+
## (一)测试 Heading 处理,应该忽略#号后再处理。
51+
###测试 Heading 处理,应该忽略#号后再处理。
52+
#### 测试 Heading 处理,应该忽略#号后再处理!
53+
4654
> 引用文本:Quote 也是可以的。
4755
4856
```rust

0 commit comments

Comments
 (0)
Please sign in to comment.