diff options
| author | John MacFarlane <[email protected]> | 2023-07-12 08:43:26 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-07-12 09:13:32 -0700 |
| commit | 29c5afb305c32129db4e81cd489cd3bd2a14c2e9 (patch) | |
| tree | f374ef2ee808802dee471d0a218fdfbe91e6fded /src/Text | |
| parent | 21b51d214d10062fd3f128814832beb12d11e804 (diff) | |
RST writer: fix figure handling.
This fixes a number of regressions from pandoc 2.x.
Properly handle caption, alt attribute in figures.
No longer treat a paragraph with a single image in it as a figure
(we have a dedicated Figure element now).
Closes #8930, closes #8871.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index a9ee4694d..8d6c47fc3 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -262,21 +262,6 @@ blockToRST (Div (ident,classes,_kvs) bs) = do nest 3 contents $$ blankline blockToRST (Plain inlines) = inlineListToRST inlines -blockToRST (Para [Image attr txt (src, _)]) = do - description <- inlineListToRST txt - dims <- imageDimsToRST attr - let fig = "image:: " <> literal src - alt | null txt = empty - | otherwise = ":alt: " <> description - capt = empty - (_,cls,_) = attr - classes = case cls of - [] -> empty - ["align-right"] -> ":align: right" - ["align-left"] -> ":align: left" - ["align-center"] -> ":align: center" - _ -> ":class: " <> literal (T.unwords cls) - return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline blockToRST (Para inlines) | LineBreak `elem` inlines = linesToLineBlock $ splitBy (==LineBreak) inlines @@ -394,13 +379,21 @@ blockToRST (DefinitionList items) = do -- ensure that sublists have preceding blank line return $ blankline $$ vcat contents $$ blankline -blockToRST (Figure (ident, classes, _) _ body) = do +blockToRST (Figure (ident, classes, _kvs) + (Caption _ longCapt) body) = do let figure attr txt (src, tit) = do description <- inlineListToRST txt + capt <- blockListToRST longCapt dims <- imageDimsToRST attr - let fig = "figure:: " <> literal src - alt = ":alt: " <> if T.null tit then description else literal tit - capt = description + let fig = "figure::" <+> literal src + alt = if null txt + then if T.null tit + then empty + else ":alt:" <+> literal tit + else ":alt:" <+> description + name = if T.null ident + then empty + else "name:" <+> literal ident (_,cls,_) = attr align = case cls of [] -> empty @@ -408,7 +401,7 @@ blockToRST (Figure (ident, classes, _) _ body) = do ["align-left"] -> ":align: left" ["align-center"] -> ":align: center" _ -> ":figclass: " <> literal (T.unwords cls) - return $ hang 3 ".. " (fig $$ alt $$ align $$ dims $+$ capt) + return $ hang 3 ".. " (fig $$ name $$ alt $$ align $$ dims $+$ capt) $$ blankline case body of [Para [Image attr txt tgt]] -> figure attr txt tgt |
