Skip to content

Commit

Permalink
Clean-up the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lierdakil committed Dec 15, 2024
1 parent 40852a9 commit cba2f23
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ runSubfigures (label, cls, attrs) images caption = do
= perc/100.0
| otherwise = error "Only percent allowed in subfigure width!"
blkToRow :: Block -> [Block]
blkToRow (Para inls) = map inlToCell $ zip widths $ mapMaybe getImg inls
blkToRow (Para inls) = zipWith inlToCell widths $ mapMaybe getImg inls
blkToRow x = [x]
getImg x@Image{} = Just x
getImg (Image (id', cs, as) txt tgt) = Just (id', cs, as, txt, tgt)
getImg _ = Nothing
inlToCell :: (Double, Inline) -> Block
inlToCell (w, Image (id', cs, as) txt tgt) =
inlToCell w (id', cs, as, txt, tgt) =
Figure (id', cs, []) (Caption Nothing [Para txt]) [Plain [Image ("", cs, setW w as) txt tgt]]
inlToCell _ = error "impossible"
setW w as
-- With docx, since pandoc 3.0, 100% is interpreted as "page width",
-- even in table cells. Hence, this hack.
| isDocxFormat opts = ("width", T.pack (show $ w * 100) <> "%"):filter ((/="width") . fst) as
| otherwise = ("width", "100%"):filter ((/="width") . fst) as
setW w as = ("width", width):filter ((/="width") . fst) as
where
-- With docx, since pandoc 3.0, 100% is interpreted as "page width",
-- even in table cells. Hence, this hack.
width
| isDocxFormat opts = T.pack (show $ w * 100) <> "%"
| otherwise = "100%"

replaceSubfigs :: [Inline] -> WS (ReplacedResult [Inline])
replaceSubfigs = (replaceNoRecurse . concat) <=< mapM replaceSubfig
Expand Down

0 comments on commit cba2f23

Please sign in to comment.