mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-17 17:39:54 +08:00
RST reader: parse :alt: on figure.
Also give a better default if `alt` is not specified, using the stringified caption rather than the filename. Partially addresses #11140. Add failing test case for Markdown writer issue in #11140.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
{alt="my alt"}
|
||||
```
|
||||
|
||||
+22
-1
@@ -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" , "" )
|
||||
]
|
||||
]
|
||||
|
||||
@@ -24,7 +24,14 @@
|
||||
[ Plain
|
||||
[ Image
|
||||
( "" , [] , [ ( "width" , "1in" ) ] )
|
||||
[ Str "example.png" ]
|
||||
[ Str "This"
|
||||
, Space
|
||||
, Str "is"
|
||||
, Space
|
||||
, Str "a"
|
||||
, Space
|
||||
, Str "caption."
|
||||
]
|
||||
( "example.png" , "" )
|
||||
]
|
||||
]
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
(Caption Nothing [ Plain [ Str "capt" ] ])
|
||||
[ Plain
|
||||
[ Image
|
||||
( "" , [] , [] )
|
||||
[ Str "img/dummy.png" ]
|
||||
( "img/dummy.png" , "" )
|
||||
( "" , [] , [] ) [ Str "capt" ] ( "img/dummy.png" , "" )
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user