RST writer: properly handle images with same alt text.
Previously we created duplicate references for these in rendering RST. Closes #6194.
This commit is contained in:
parent
3e52c402d0
commit
f268ae3035
2 changed files with 32 additions and 7 deletions
|
@ -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'
|
||||
|
|
14
test/command/6194.md
Normal file
14
test/command/6194.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
```
|
||||
% pandoc -f markdown -t rst
|
||||
image1: ![foo](x.png)
|
||||
|
||||
image2: ![foo](y.png)
|
||||
^D
|
||||
image1: |foo|
|
||||
|
||||
image2: |image1|
|
||||
|
||||
.. |foo| image:: x.png
|
||||
.. |image1| image:: y.png
|
||||
```
|
||||
|
Loading…
Reference in a new issue