Skip to content

Commit

Permalink
RST reader: fix double-link bug.
Browse files Browse the repository at this point in the history
Link labels containing raw URLs were parsed as autolinks,
but links within links are not allowed.

Closes #4581.
  • Loading branch information
jgm committed Jul 22, 2018
1 parent 748aa92 commit 6419819
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Text/Pandoc/Readers/RST.hs
Expand Up @@ -45,6 +45,7 @@ import Data.Maybe (fromMaybe, isJust)
import Data.Sequence (ViewR (..), viewr)
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Walk (walk)
import Text.Pandoc.Builder (Blocks, Inlines, fromList, setMeta, trimInlines)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class (PandocMonad, fetchItem, readFileFromDirs)
Expand Down Expand Up @@ -1479,7 +1480,7 @@ explicitLink :: PandocMonad m => RSTParser m Inlines
explicitLink = try $ do
char '`'
notFollowedBy (char '`') -- `` marks start of inline code
label' <- trimInlines . mconcat <$>
label' <- removeLinks . trimInlines . mconcat <$>
manyTill (notFollowedBy (char '`') >> inline) (char '<')
src <- trim <$> manyTill (noneOf ">\n") (char '>')
skipSpaces
Expand All @@ -1494,6 +1495,12 @@ explicitLink = try $ do
_ -> return ((src, ""), nullAttr)
return $ B.linkWith attr (escapeURI src') tit label''

removeLinks :: B.Inlines -> B.Inlines
removeLinks = B.fromList . walk (concatMap go) . B.toList
where go :: Inline -> [Inline]
go (Link _ lab _) = lab
go x = [x]

citationName :: PandocMonad m => RSTParser m String
citationName = do
raw <- citationMarker
Expand Down
6 changes: 6 additions & 0 deletions test/command/4581.md
@@ -0,0 +1,6 @@
```
% pandoc -f rst -t native
`http://loc <http://loc>`__
^D
[Para [Link ("",[],[]) [Str "http://loc"] ("http://loc","")]]
```

0 comments on commit 6419819

Please sign in to comment.