@@ -168,10 +168,20 @@ referenceKey = try $ do
168168 optional (char '<')
169169 src <- many (noneOf "> \n\t")
170170 optional (char '>')
171− tit <- option "" title
171+ tit <- option "" referenceTitle
172172 blanklines
173173 return $ KeyBlock label (removeTrailingSpace src, tit)
174174
175+referenceTitle = try $ do
176+ skipSpaces
177+ optional newline
178+ skipSpaces
179+ tit <- (charsInBalanced '(' ')' >>= return . unwords . words)
180+ <|> do delim <- char '\'' <|> char '"'
181+ manyTill anyChar (try (char delim >> skipSpaces >>
182+ notFollowedBy (noneOf ")\n")))
183+ return $ decodeCharacterReferences tit
184+
175185noteMarker = string "[^" >> manyTill (noneOf " \t\n") (char ']')
176186
177187rawLine = try $ do
@@ -793,25 +803,20 @@ source = try $ do
793803 optional (char '<')
794804 src <- many (noneOf ")> \t\n")
795805 optional (char '>')
796− tit <- option "" title
806+ tit <- option "" linkTitle
797807 skipSpaces
798808 char ')'
799809 return (removeTrailingSpace src, tit)
800810
801−titleWith startChar endChar = try $ do
802− leadingSpace <- many1 (oneOf " \t\n")
803− if length (filter (=='\n') leadingSpace) > 1
804− then fail "title must be separated by space and on same or next line"
805− else return ()
806− char startChar
807− tit <- manyTill anyChar (try (char endChar >> skipSpaces >>
808− notFollowedBy (noneOf ")\n")))
811+linkTitle = try $ do
812+ skipSpaces
813+ optional newline
814+ skipSpaces
815+ delim <- char '\'' <|> char '"'
816+ tit <- manyTill anyChar (try (char delim >> skipSpaces >>
817+ notFollowedBy (noneOf ")\n")))
809818 return $ decodeCharacterReferences tit
810819
811−title = choice [ titleWith '(' ')',
812− titleWith '"' '"',
813− titleWith '\'' '\''] <?> "title"
814−
815820link = try $ do
816821 label <- reference
817822 src <- source <|> referenceLink label