Skip to content

Commit

Permalink
Fix markdown for support mark in link text.
Browse files Browse the repository at this point in the history
e.g.: `[\`Hello\`](/hello)`, `[**Hello**](/hello)`
  • Loading branch information
huacnlee committed Feb 8, 2023
1 parent faf7774 commit d650d5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions autocorrect/grammar/markdown.pest
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ image_prefix = @{ "!" }
img = ${ image_prefix ~ link }

/// Matches link, e.g.: `[Hello](/hello)` or `[Hello]`
link = ${ link_string ~ href? }
link_string = { "[" ~ (!("]") ~ ANY)* ~ "]" }
link = ${ link_string_wrap ~ href? }
link_string_wrap = { open_bracket ~ (mark* ~ link_string ~ mark*) ~ close_bracket }
link_string = @{ (!(close_bracket) ~ ANY)* }
open_bracket = @{ "[" }
close_bracket = @{ "]" }
href = @{ paren }

wikilinks = ${"[[" ~ (!("]]") ~ ANY)* ~ "]]" }

mark = ${ PUSH(open_mark) ~ (mark | mark_string) ~ close_mark }
open_mark = @{ "***" | "**" | "*" | "~~" | "`" | "\"" }
mark = ${ code | PUSH(open_mark) ~ (mark | mark_string) ~ close_mark }
open_mark = @{ "***" | "**" | "*" | "~~" | "\"" }
close_mark = @{ POP }
mark_string = { (!(PEEK | inline) ~ ANY)* }

Expand Down
4 changes: 4 additions & 0 deletions autocorrect/src/code/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ mod tests {
[Link
支持Soft换行](https://google.com)
[`code代码在Link里面`](/zh-CN/docs/Web/API/Blob)方法将每个.
它指向一个[示例](#示例)
## This is list
Expand Down Expand Up @@ -173,6 +175,8 @@ mod tests {
[Link
支持 Soft 换行](https://google.com)
[`code代码在Link里面`](/zh-CN/docs/Web/API/Blob)方法将每个。
它指向一个[示例](#示例)
## This is list
Expand Down

0 comments on commit d650d5b

Please sign in to comment.