git.iko.soy/typeable/pandoc
on master help sign in
RST writer: proper handling of :align: on figures, images.

When the image has the `align-right` (etc.) class, we now use an `:align:` attribute. Closes #4420.

commita3729ef2da06aca1799bdd57ada12f47c04b93e2 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 9 Oct 2019, 15:05 (7 years ago) parent5ec9044
2 files changed+34−6
src/Text/Pandoc/Writers/RST.hs+12−6 test/command/4420.md+22
src/Text/Pandoc/Writers/RST.hs+12−6
@@ -140,9 +140,12 @@ pictToRST (label, (attr, src, _, mbtarget)) = do
140140 label' <- inlineListToRST label
141141 dims <- imageDimsToRST attr
142142 let (_, cls, _) = attr
143− classes = if null cls
144− then empty
145− else ":class: " <> text (unwords cls)
143+ classes = case cls of
144+ [] -> empty
145+ ["align-right"] -> ":align: right"
146+ ["align-left"] -> ":align: left"
147+ ["align-center"] -> ":align: center"
148+ _ -> ":class: " <> text (unwords cls)
146149 return $ nowrap
147150 $ ".. |" <> label' <> "| image:: " <> text src $$ hang 3 empty (classes $$ dims)
148151 $$ case mbtarget of
@@ -218,9 +221,12 @@ blockToRST (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
218221 let fig = "figure:: " <> text src
219222 alt = ":alt: " <> if null tit then capt else text tit
220223 (_,cls,_) = attr
221− classes = if null cls
222− then empty
223− else ":figclass: " <> text (unwords cls)
224+ classes = case cls of
225+ [] -> empty
226+ ["align-right"] -> ":align: right"
227+ ["align-left"] -> ":align: left"
228+ ["align-center"] -> ":align: center"
229+ _ -> ":figclass: " <> text (unwords cls)
224230 return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
225231blockToRST (Para inlines)
226232 | LineBreak `elem` inlines =
test/command/4420.mdnew file+22
@@ -0,0 +1,22 @@
1+```
2+% pandoc -f native -t rst
3+[Image ("",["align-right"],[("width","100px")]) [Str "image"] ("foo.png","")]
4+^D
5+|image|
6+
7+.. |image| image:: foo.png
8+ :align: right
9+ :width: 100px
10+```
11+
12+```
13+% pandoc -f native -t rst
14+[Para [Image ("",["align-right"],[("width","100px")]) [Str "image"] ("foo.png","fig:test")]]
15+^D
16+.. figure:: foo.png
17+ :alt: test
18+ :align: right
19+ :width: 100px
20+
21+ image
22+```