git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: don't lose parentheses in URLs.
db3d411John MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+7−3
@@ -287,8 +287,7 @@ referenceKey = try $ do
287referenceTitle :: MarkdownParser String
287referenceTitle :: MarkdownParser String
288referenceTitle = try $ do
288referenceTitle = try $ do
289 skipSpaces >> optional newline >> skipSpaces
289 skipSpaces >> optional newline >> skipSpaces
290− let parenTit = charsInBalanced '(' ')' litChar
290+ quotedTitle '"' <|> quotedTitle '\'' <|> charsInBalanced '(' ')' litChar
291− quotedTitle '"' <|> quotedTitle '\'' <|> parenTit
292
291
293-- A link title in quotes
292-- A link title in quotes
294quotedTitle :: Char -> MarkdownParser String
293quotedTitle :: Char -> MarkdownParser String
@@ -1494,13 +1493,18 @@ reference :: MarkdownParser (F Inlines, String)
1494reference = do notFollowedBy' (string "[^") -- footnote reference
1493reference = do notFollowedBy' (string "[^") -- footnote reference
1495 withRaw $ trimInlinesF <$> inlinesInBalancedBrackets
1494 withRaw $ trimInlinesF <$> inlinesInBalancedBrackets
1496
1495
1496+parenthesizedChars :: MarkdownParser [Char]
1497+parenthesizedChars = do
1498+ result <- charsInBalanced '(' ')' litChar
1499+ return $ '(' : result ++ ")"
1500+
1497-- source for a link, with optional title
1501-- source for a link, with optional title
1498source :: MarkdownParser (String, String)
1502source :: MarkdownParser (String, String)
1499source = do
1503source = do
1500 char '('
1504 char '('
1501 skipSpaces
1505 skipSpaces
1502 let urlChunk = try $ notFollowedBy (oneOf "\"')") >>
1506 let urlChunk = try $ notFollowedBy (oneOf "\"')") >>
1503− (charsInBalanced '(' ')' litChar <|> count 1 litChar)
1507+ (parenthesizedChars <|> count 1 litChar)
1504 let sourceURL = (unwords . words . concat) <$> many urlChunk
1508 let sourceURL = (unwords . words . concat) <$> many urlChunk
1505 let betweenAngles = try $
1509 let betweenAngles = try $
1506 char '<' >> manyTill litChar (char '>')
1510 char '<' >> manyTill litChar (char '>')
tests/markdown-reader-more.native+5−1
@@ -130,4 +130,8 @@
130,Para [Link [Str "link"] ("/\252rl","\246\246!")]
130,Para [Link [Str "link"] ("/\252rl","\246\246!")]
131,Para [Link [Str "http://g\246\246gle.com"] ("http://g\246\246gle.com","")]
131,Para [Link [Str "http://g\246\246gle.com"] ("http://g\246\246gle.com","")]
132,Para [Link [Str "me@ex\228mple.com"] ("mailto:me@ex\228mple.com","")]
132,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
221[foobar]
221[foobar]
222
222
223[foobar]: /&uuml;rl "&ouml;&ouml;!"
223[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))