@@ -168,8 +168,8 @@ referenceKey = try $ do
168168 optional (char '<')
169169 src <- many (noneOf "> \n\t")
170170 optional (char '>')
171− tit <- option "" referenceTitle
172− blanklines
171+ tit <- option "" referenceTitle
172+ blanklines
173173 return $ KeyBlock label (removeTrailingSpace src, tit)
174174
175175referenceTitle = try $ do
@@ -178,7 +178,8 @@ referenceTitle = try $ do
178178 skipSpaces
179179 tit <- (charsInBalanced '(' ')' >>= return . unwords . words)
180180 <|> do delim <- char '\'' <|> char '"'
181− manyTill anyChar (try (char delim >> blankline))
181+ manyTill anyChar (try (char delim >> skipSpaces >>
182+ notFollowedBy (noneOf ")\n")))
182183 return $ decodeCharacterReferences tit
183184
184185noteMarker = string "[^" >> manyTill (noneOf " \t\n") (char ']')
@@ -825,8 +826,8 @@ link = try $ do
825826
826827-- a link like [this][ref] or [this][] or [this]
827828referenceLink label = do
828− ref <- option [] (try (skipSpaces >> optional newline >>
829− skipSpaces >> reference))
829+ ref <- option [] (try (optional (char ' ') >>
830+ optional (newline >> skipSpaces) >> reference))
830831 let ref' = if null ref then label else ref
831832 state <- getState
832833 case lookupKeySrc (stateKeys state) ref' of