diff options
| author | John MacFarlane <[email protected]> | 2022-11-29 09:13:48 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-11-29 09:13:48 -0800 |
| commit | 07ebafcb011abda5c6a5f2d0f4d10e09417285e7 (patch) | |
| tree | f646d7aa8cb95cefa031755b4e63f09cd818a98c | |
| parent | b6622c07b6db097ad50ee2d9ae0ec4d7ba991615 (diff) | |
DocBook reader: parse title from imageobject/objectinfo.
See #8437.
| -rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 2e594bf73..6ccb3ef26 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -804,24 +804,30 @@ getMediaobject :: PandocMonad m => Element -> DB m Inlines getMediaobject e = do figTitle <- gets dbFigureTitle ident <- gets dbFigureId - (imageUrl, attr) <- - case filterElements (named "imageobject") e of - [] -> return (mempty, nullAttr) - (z:_) -> case filterChild (named "imagedata") z of - Nothing -> return (mempty, nullAttr) - Just i -> let atVal a = attrValue a i - w = case atVal "width" of - "" -> [] - d -> [("width", d)] - h = case atVal "depth" of - "" -> [] - d -> [("height", d)] - id' = case atVal "id" of - x | T.null x -> ident - | otherwise -> x - cs = T.words $ atVal "role" - atr = (id', cs, w ++ h) - in return (atVal "fileref", atr) + let (imageUrl, tit, attr) = + case filterElements (named "imageobject") e of + [] -> (mempty, mempty, nullAttr) + (z:_) -> + let tit' = maybe "" (T.strip . strContent) $ + filterChild (named "objectinfo") z >>= + filterChild (named "title") + (imageUrl', attr') = + case filterChild (named "imagedata") z of + Nothing -> (mempty, nullAttr) + Just i -> let atVal a = attrValue a i + w = case atVal "width" of + "" -> [] + d -> [("width", d)] + h = case atVal "depth" of + "" -> [] + d -> [("height", d)] + id' = case atVal "id" of + x | T.null x -> ident + | otherwise -> x + cs = T.words $ atVal "role" + atr = (id', cs, w ++ h) + in (atVal "fileref", atr) + in (imageUrl', tit', attr') let getCaption el = case filterChild (\x -> named "caption" x || named "textobject" x || named "alt" x) el of @@ -829,8 +835,8 @@ getMediaobject e = do Just z -> mconcat <$> mapM parseInline (elContent z) let (capt, title) = if null figTitle - then (getCaption e, "") - else (return figTitle, "fig:") + then (getCaption e, tit) + else (return figTitle, "fig:" <> tit) fmap (imageWith attr imageUrl title) capt getBlocks :: PandocMonad m => Element -> DB m Blocks |
