RST reader: fix anonymous redirects with backticks.

Closes #4598.
This commit is contained in:
John MacFarlane 2018-04-26 12:10:39 -07:00
parent 50da88446c
commit a96c762a10
2 changed files with 18 additions and 3 deletions

View file

@ -1090,10 +1090,15 @@ targetURI :: Monad m => ParserT [Char] st m [Char]
targetURI = do
skipSpaces
optional newline
contents <- many1 (try (many spaceChar >> newline >>
many1 spaceChar >> noneOf " \t\n") <|> noneOf "\n")
contents <- trim <$>
many1 (satisfy (/='\n')
<|> try (newline >> many1 spaceChar >> noneOf " \t\n"))
blanklines
return $ escapeURI $ trim contents
case reverse contents of
-- strip backticks
'_':'`':xs -> return (dropWhile (=='`') (reverse xs) ++ "_")
'_':_ -> return contents
_ -> return (escapeURI contents)
substKey :: PandocMonad m => RSTParser m ()
substKey = try $ do

10
test/command/4598.md Normal file
View file

@ -0,0 +1,10 @@
```
% pandoc -f rst
`x`__
__ `xy`_
.. _`xy`: http://xy.org
^D
<p><a href="http://xy.org">x</a></p>
```