diff --git a/autocorrect/grammar/markdown.pest b/autocorrect/grammar/markdown.pest index 15b08643..dd5034c9 100644 --- a/autocorrect/grammar/markdown.pest +++ b/autocorrect/grammar/markdown.pest @@ -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 = @{ (" ")* } @@ -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 } \ No newline at end of file +string = ${ (!(newline) ~ ANY)* } + diff --git a/autocorrect/src/code/markdown.rs b/autocorrect/src/code/markdown.rs index 2d5aaecb..4d6caf9a 100644 --- a/autocorrect/src/code/markdown.rs +++ b/autocorrect/src/code/markdown.rs @@ -38,7 +38,10 @@ mod tests { ###测试Heading处理,应该忽略#号后再处理. #### 测试Heading处理,应该忽略#号后再处理! + - 【括号】测试中文符号在List里面 + > 引用文本:Quote也是可以的。 + > (括号)在Quote里面 ```rust // Codeblock里面也会处理 @@ -86,7 +89,10 @@ mod tests { ###测试 Heading 处理,应该忽略#号后再处理。 #### 测试 Heading 处理,应该忽略#号后再处理! + - 【括号】测试中文符号在 List 里面 + > 引用文本:Quote 也是可以的。 + > (括号)在 Quote 里面 ```rust // Codeblock 里面也会处理