Skip to content

Commit

Permalink
Fix #44 avoid remove space prefix within Markdown list, quote case.
Browse files Browse the repository at this point in the history
Improve Markdown parser details for know the List, Quote as Block, and Image, Link, Code as Inline.
  • Loading branch information
huacnlee committed May 26, 2022
1 parent 4cbf2a4 commit 115da18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
25 changes: 16 additions & 9 deletions autocorrect/grammar/markdown.pest
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
para = { ANY* ~ NEWLINE{2} }
expr = _{ codeblock | img | link | td_tag | heading }
item = _{ SOI ~ line* ~ EOI }
line = _{ expr | text | newline }

inline = _{ img | link | mark }
block = ${ PUSH(block_prefix) ~ space ~ (inline | string) }

expr = _{ codeblock | inline | td_tag | block }
text = { (!(expr | newline) ~ ANY)+ }
newline = ${ "\n" | "\r" }
space = @{ (" ")* }
Expand All @@ -15,16 +20,18 @@ mark_tag = @{
| "~~"
| "`"
}
heading_tag = @{"######" | "#####" | "####" | "###" | "##" | "#"}
block_prefix = @{
"######" | "#####" | "####" | "###" | "##" | "#" | "*" | "-" | ">"
}

image_prefix = @{ "!" }
img = ${ image_prefix ~ link }

img_start = @{ "!" }
img = ${ img_start ~ link }
link = ${ link_string ~ link_url }
link_string = { "[" ~ (!("]" | newline) ~ ANY)* ~ "]" }
link_url = { "(" ~ (!(")" | newline) ~ ANY)* ~ ")" }

mark = ${ PUSH(mark_tag) ~ string ~ PUSH(mark_tag) }
heading = ${ PUSH(heading_tag) ~ space ~ string }
string = ${ (!(PEEK | newline) ~ ANY)* }

line = _{ expr | text | newline }
item = _{ SOI ~ line* ~ EOI }
string = ${ (!(newline) ~ ANY)* }

6 changes: 6 additions & 0 deletions autocorrect/src/code/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ mod tests {
###测试Heading处理,应该忽略#号后再处理.
#### 测试Heading处理,应该忽略#号后再处理!
- 【括号】测试中文符号在List里面
> 引用文本:Quote也是可以的。
> (括号)在Quote里面
```rust
// Codeblock里面也会处理
Expand Down Expand Up @@ -86,7 +89,10 @@ mod tests {
###测试 Heading 处理,应该忽略#号后再处理。
#### 测试 Heading 处理,应该忽略#号后再处理!
- 【括号】测试中文符号在 List 里面
> 引用文本:Quote 也是可以的。
> (括号)在 Quote 里面
```rust
// Codeblock 里面也会处理
Expand Down

0 comments on commit 115da18

Please sign in to comment.