Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown: allow URLs with nested parenthesis in links #514

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading