git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: don't lose parentheses in URLs.

Added tests. This fixes a regression from 1.10.x. Closes #786.

commitdb3d4113a2c3ef8f36329f08afa02828df79ec75 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 13 Mar 2013, 19:18 (14 years ago) parentd820eb2
3 files changed+22−4
src/Text/Pandoc/Readers/Markdown.hs+7−3 tests/markdown-reader-more.native+5−1 tests/markdown-reader-more.txt+10
src/Text/Pandoc/Readers/Markdown.hs+7−3
@@ -287,8 +287,7 @@ referenceKey = try $ do
287287referenceTitle :: MarkdownParser String
288288referenceTitle = try $ do
289289 skipSpaces >> optional newline >> skipSpaces
290− let parenTit = charsInBalanced '(' ')' litChar
291− quotedTitle '"' <|> quotedTitle '\'' <|> parenTit
290+ quotedTitle '"' <|> quotedTitle '\'' <|> charsInBalanced '(' ')' litChar
292291
293292-- A link title in quotes
294293quotedTitle :: Char -> MarkdownParser String
@@ -1494,13 +1493,18 @@ reference :: MarkdownParser (F Inlines, String)
14941493reference = do notFollowedBy' (string "[^") -- footnote reference
14951494 withRaw $ trimInlinesF <$> inlinesInBalancedBrackets
14961495
1496+parenthesizedChars :: MarkdownParser [Char]
1497+parenthesizedChars = do
1498+ result <- charsInBalanced '(' ')' litChar
1499+ return $ '(' : result ++ ")"
1500+
14971501-- source for a link, with optional title
14981502source :: MarkdownParser (String, String)
14991503source = do
15001504 char '('
15011505 skipSpaces
15021506 let urlChunk = try $ notFollowedBy (oneOf "\"')") >>
1503− (charsInBalanced '(' ')' litChar <|> count 1 litChar)
1507+ (parenthesizedChars <|> count 1 litChar)
15041508 let sourceURL = (unwords . words . concat) <$> many urlChunk
15051509 let betweenAngles = try $
15061510 char '<' >> manyTill litChar (char '>')
tests/markdown-reader-more.native+5−1
@@ -130,4 +130,8 @@
130130,Para [Link [Str "link"] ("/\252rl","\246\246!")]
131131,Para [Link [Str "http://g\246\246gle.com"] ("http://g\246\246gle.com","")]
132132,Para [Link [Str "me@ex\228mple.com"] ("mailto:me@ex\228mple.com","")]
133−,Para [Link [Str "foobar"] ("/\252rl","\246\246!")]]
133+,Para [Link [Str "foobar"] ("/\252rl","\246\246!")]
134+,Header 2 ("parentheses-in-urls",[],[]) [Str "Parentheses",Space,Str "in",Space,Str "URLs"]
135+,Para [Link [Str "link"] ("/hi(there)","")]
136+,Para [Link [Str "link"] ("/hithere)","")]
137+,Para [Link [Str "linky"] ("hi_(there_(nested))","")]]
tests/markdown-reader-more.txt+10
@@ -221,3 +221,13 @@ Empty cells
221221[foobar]
222222
223223[foobar]: /&uuml;rl "&ouml;&ouml;!"
224+
225+## Parentheses in URLs
226+
227+[link](/hi(there))
228+
229+[link](/hithere\))
230+
231+[linky]
232+
233+[linky]: hi_(there_(nested))