RST reader: fix double-link bug.
Link labels containing raw URLs were parsed as autolinks, but links within links are not allowed. Closes #4581.
This commit is contained in:
parent
748aa920f6
commit
6419819b46
2 changed files with 14 additions and 1 deletions
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
6
test/command/4581.md
Normal file
6
test/command/4581.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
```
|
||||
% pandoc -f rst -t native
|
||||
`http://loc <http://loc>`__
|
||||
^D
|
||||
[Para [Link ("",[],[]) [Str "http://loc"] ("http://loc","")]]
|
||||
```
|
Loading…
Reference in a new issue