git.iko.soy/typeable/pandoc
on master help sign in
RST reader: fix double-link bug.

Link labels containing raw URLs were parsed as autolinks, but links within links are not allowed. Closes #4581.

commit6419819b46c0d69c7024ba8aa4a6381cb311341c authorJohn MacFarlane <jgm@berkeley.edu> dateSat 21 Jul 2018, 22:51 (8 years ago) parent748aa92
2 files changed+14−1
src/Text/Pandoc/Readers/RST.hs+8−1 test/command/4581.md+6
src/Text/Pandoc/Readers/RST.hs+8−1
@@ -45,6 +45,7 @@ import Data.Maybe (fromMaybe, isJust)
4545import Data.Sequence (ViewR (..), viewr)
4646import Data.Text (Text)
4747import qualified Data.Text as T
48+import Text.Pandoc.Walk (walk)
4849import Text.Pandoc.Builder (Blocks, Inlines, fromList, setMeta, trimInlines)
4950import qualified Text.Pandoc.Builder as B
5051import Text.Pandoc.Class (PandocMonad, fetchItem, readFileFromDirs)
@@ -1479,7 +1480,7 @@ explicitLink :: PandocMonad m => RSTParser m Inlines
14791480explicitLink = try $ do
14801481 char '`'
14811482 notFollowedBy (char '`') -- `` marks start of inline code
1482− label' <- trimInlines . mconcat <$>
1483+ label' <- removeLinks . trimInlines . mconcat <$>
14831484 manyTill (notFollowedBy (char '`') >> inline) (char '<')
14841485 src <- trim <$> manyTill (noneOf ">\n") (char '>')
14851486 skipSpaces
@@ -1494,6 +1495,12 @@ explicitLink = try $ do
14941495 _ -> return ((src, ""), nullAttr)
14951496 return $ B.linkWith attr (escapeURI src') tit label''
14961497
1498+removeLinks :: B.Inlines -> B.Inlines
1499+removeLinks = B.fromList . walk (concatMap go) . B.toList
1500+ where go :: Inline -> [Inline]
1501+ go (Link _ lab _) = lab
1502+ go x = [x]
1503+
14971504citationName :: PandocMonad m => RSTParser m String
14981505citationName = do
14991506 raw <- citationMarker
test/command/4581.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+% pandoc -f rst -t native
3+`http://loc <http://loc>`__
4+^D
5+[Para [Link ("",[],[]) [Str "http://loc"] ("http://loc","")]]
6+```