diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 989aab3ac..7158b804e 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -855,8 +855,9 @@ directive' = do let figcls = concatMap (T.words . snd) figclasskv let figattr = ("", figcls ++ aligncls, []) let capt = B.caption Nothing (B.plain caption <> legend) + let alt = maybe caption (B.text . trim) (lookup "alt" fields) return $ B.figureWith figattr capt $ - B.plain (B.imageWith (imgident, imgcls, imgkvs) src "" (B.text src)) + B.plain (B.imageWith (imgident, imgcls, imgkvs) src "" alt) "image" -> do let src = escapeURI $ trim top let alt = B.str $ maybe "image" trim $ lookup "alt" fields diff --git a/test/command/11140.md b/test/command/11140.md new file mode 100644 index 000000000..a9db61dbb --- /dev/null +++ b/test/command/11140.md @@ -0,0 +1,52 @@ +``` +% pandoc -f rst -t native +.. figure:: image.png + :alt: my alt + + Caption +^D +[ Figure + ( "" , [] , [] ) + (Caption Nothing [ Plain [ Str "Caption" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "my" , Space , Str "alt" ] + ( "image.png" , "" ) + ] + ] +] +``` + +``` +% pandoc -f rst -t native +.. figure:: image.png + + Caption +^D +[ Figure + ( "" , [] , [] ) + (Caption Nothing [ Plain [ Str "Caption" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) [ Str "Caption" ] ( "image.png" , "" ) + ] + ] +] +``` + +``` +% pandoc -f native -t markdown +[ Figure + ( "" , [] , [] ) + (Caption + Nothing [ Plain [ Str "Caption" ] ]) + [ Plain + [ Image ( "" , [] , [] ) [ Str "my", Space, Str "alt" ] ( "image.png" , "" ) + ] + ] +] +^D +![Caption](image.png){alt="my alt"} +``` + diff --git a/test/command/5619.md b/test/command/5619.md index 7eec80cfd..7247ac5f6 100644 --- a/test/command/5619.md +++ b/test/command/5619.md @@ -37,7 +37,28 @@ [ Plain [ Image ( "test" , [] , [ ( "width" , "1in" ) ] ) - [ Str "img1.jpg" ] + [ Str "The" + , Space + , Str "caption." + , Space + , Str "Here's" + , Space + , Str "what" + , Space + , Str "piggybacking" + , Space + , Str "on" + , Space + , Str "caption" + , Space + , Str "would" + , Space + , Str "look" + , Space + , Str "like" + , Space + , Str "{#fig:1}" + ] ( "img1.jpg" , "" ) ] ] diff --git a/test/command/7473.md b/test/command/7473.md index 3cc281fc7..cb71a2075 100644 --- a/test/command/7473.md +++ b/test/command/7473.md @@ -24,7 +24,14 @@ [ Plain [ Image ( "" , [] , [ ( "width" , "1in" ) ] ) - [ Str "example.png" ] + [ Str "This" + , Space + , Str "is" + , Space + , Str "a" + , Space + , Str "caption." + ] ( "example.png" , "" ) ] ] diff --git a/test/command/rst_block_subst.md b/test/command/rst_block_subst.md index fe0af7d94..c279b1c25 100644 --- a/test/command/rst_block_subst.md +++ b/test/command/rst_block_subst.md @@ -11,9 +11,7 @@ (Caption Nothing [ Plain [ Str "capt" ] ]) [ Plain [ Image - ( "" , [] , [] ) - [ Str "img/dummy.png" ] - ( "img/dummy.png" , "" ) + ( "" , [] , [] ) [ Str "capt" ] ( "img/dummy.png" , "" ) ] ] ]