Skip to content

Commit

Permalink
Markdown spec compliance: allow URLs with nested parenthesis (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshalm authored Sep 4, 2023
1 parent a0d9639 commit 88d8b96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ object InlineParsers {
def enclosedIn(delim: String): Parser[String] =
delim ~> delimitedBy(delim <~ lookAhead(titleEnd))
val title = ws.void ~> (enclosedIn("\"") | enclosedIn("'"))
val nestedParens = ("(" ~ delimitedBy(')')).source

val url = ("<" ~> text(delimitedBy('>')).embed(recParsers.escapeSequence)) |
text(delimitedBy(')', ' ', '\t').keepDelimiter).embed(recParsers.escapeSequence)
text(delimitedBy(')', ' ', '\t').keepDelimiter).embedAll(
Seq(recParsers.escapeSequence, nestedParens)
)

val urlWithTitle =
("(" ~> url ~ opt(title) <~ ws ~ ")").mapN(TargetUrl.apply).withCursor.map(t =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ class InlineParsersSpec extends FunSuite with TestSourceBuilders {
runEnclosed("some [link](http://foo) here", SpanLink.external("http://foo")("link"))
}

test("links - inline link with nested parenthesis") {
runEnclosed(
"some [link](http://foo?param=foo(bar)baz) here",
SpanLink.external("http://foo?param=foo(bar)baz")("link")
)
}

test("links - recognize email link as external link") {
runEnclosed(
"some [link](mailto:nobody@nowhere.com) here",
Expand Down

0 comments on commit 88d8b96

Please sign in to comment.