fix attrs for implicit figures

the syntax `![caption](path){.class}` (when interpreted as an implicit
figure) attaches `class` to the `<img>` tag. this moves it to the
`<figure>`
This commit is contained in:
Rhiannon Morris 2024-09-25 23:02:59 +02:00
parent 1f469f35ab
commit 99f4d7eac0

View file

@ -25,7 +25,8 @@ main = toJSONFilter filter where
defColor <- getDefColor m defColor <- getDefColor m
let ?lang = lang let ?lang = lang
let ?defColor = defColor let ?defColor = defColor
fmap (walk makeEbnf . fmap (walk fixFigureClass .
walk makeEbnf .
walk makeQuotes . walk makeQuotes .
walk (concatMap makeBlocks) . walk (concatMap makeBlocks) .
walk inlineLetterList) $ walk inlineLetterList) $
@ -51,6 +52,11 @@ pluck1 [] _ = Nothing
pluck1 (x:xs) ys = (x,) <$> pluck x ys <|> pluck1 xs ys pluck1 (x:xs) ys = (x,) <$> pluck x ys <|> pluck1 xs ys
fixFigureClass :: Block -> Block
fixFigureClass (Figure (_, c1, a1) cap [Plain [Image (i, c2, a2) alt path]]) =
Figure (i, c1 ++ c2, a1 ++ a2) cap [Plain [Image ("", [], []) alt path]]
fixFigureClass b = b
makeBlocks :: Block -> [Block] makeBlocks :: Block -> [Block]
makeBlocks (Div ("", clss, []) blks) makeBlocks (Div ("", clss, []) blks)
| Just (cls, rest) <- pluck1 ["figure", "aside"] clss = | Just (cls, rest) <- pluck1 ["figure", "aside"] clss =