diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-04-24 16:54:52 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-04-24 16:54:52 -0700 |
commit | f268ae30350e3d94e57e58e5a543d3292d204b83 (patch) | |
tree | ee4f02c6e9f765ae3790e78b3af19a4afd0433aa /src | |
parent | 3e52c402d0744f36462aeb3882d2cf2844529b0f (diff) | |
download | pandoc-f268ae30350e3d94e57e58e5a543d3292d204b83.tar.gz |
RST writer: properly handle images with same alt text.
Previously we created duplicate references for these
in rendering RST. Closes #6194.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index a390cc6cf..67603728b 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -42,6 +42,7 @@ data WriterState = , stHasRawTeX :: Bool , stOptions :: WriterOptions , stTopLevel :: Bool + , stImageId :: Int } type RST = StateT WriterState @@ -52,7 +53,7 @@ writeRST opts document = do let st = WriterState { stNotes = [], stLinks = [], stImages = [], stHasMath = False, stHasRawTeX = False, stOptions = opts, - stTopLevel = True } + stTopLevel = True, stImageId = 1 } evalStateT (pandocToRST document) st -- | Return RST representation of document. @@ -687,13 +688,23 @@ inlineToRST (Note contents) = do registerImage :: PandocMonad m => Attr -> [Inline] -> Target -> Maybe Text -> RST m (Doc Text) registerImage attr alt (src,tit) mbtarget = do pics <- gets stImages + imgId <- gets stImageId + let getImageName = do + modify $ \st -> st{ stImageId = imgId + 1 } + return [Str ("image" <> tshow imgId)] txt <- case lookup alt pics of - Just (a,s,t,mbt) | (a,s,t,mbt) == (attr,src,tit,mbtarget) - -> return alt - _ -> do - let alt' = if null alt || alt == [Str ""] - then [Str $ "image" <> tshow (length pics)] - else alt + Just (a,s,t,mbt) -> + if (a,s,t,mbt) == (attr,src,tit,mbtarget) + then return alt + else do + alt' <- getImageName + modify $ \st -> st { stImages = + (alt', (attr,src,tit, mbtarget)):stImages st } + return alt' + Nothing -> do + alt' <- if null alt || alt == [Str ""] + then getImageName + else return alt modify $ \st -> st { stImages = (alt', (attr,src,tit, mbtarget)):stImages st } return alt' |