blog/blog-meta/fix-figures.hs

15 lines
525 B
Haskell

import Text.Pandoc.JSON
main :: IO ()
main = toJSONFilter $ expandable . shaped where
expandable (Figure attr@(_, cs, _) cap [Plain img@[Image _ _ t]])
| "expandable" `elem` cs = Figure attr cap $ [Plain [Link blank img t]]
expandable b = b
blank = ("", [], [("target", "_blank")])
shaped (Figure (i, cs, as) cap [Plain img@[Image _ _ (url, _)]])
| "shaped" `elem` cs =
let shape = "shape-outside: url(" <> url <> ")" in
Figure (i, cs, ("style", shape) : as) cap [Plain img]
shaped b = b