@@ -521,6 +521,7 @@ data DBState = DBState{ dbSectionLevel :: Int
521521 , dbMeta :: Meta
522522 , dbBook :: Bool
523523 , dbFigureTitle :: Inlines
524+ , dbFigureId :: Text
524525 , dbContent :: [Content]
525526 } deriving Show
526527
@@ -530,6 +531,7 @@ instance Default DBState where
530531 , dbMeta = mempty
531532 , dbBook = False
532533 , dbFigureTitle = mempty
534+ , dbFigureId = mempty
533535 , dbContent = [] }
534536
535537
@@ -557,9 +559,10 @@ getFigure e = do
557559 tit <- case filterChild (named "title") e of
558560 Just t -> getInlines t
559561 Nothing -> return mempty
560− modify $ \st -> st{ dbFigureTitle = tit }
562+ let ident = attrValue "id" e
563+ modify $ \st -> st{ dbFigureTitle = tit, dbFigureId = ident }
561564 res <- getBlocks e
562− modify $ \st -> st{ dbFigureTitle = mempty }
565+ modify $ \st -> st{ dbFigureTitle = mempty, dbFigureId = mempty }
563566 return res
564567
565568-- normalize input, consolidating adjacent Text and CRef elements
@@ -655,6 +658,8 @@ addToStart toadd bs =
655658-- A DocBook mediaobject is a wrapper around a set of alternative presentations
656659getMediaobject :: PandocMonad m => Element -> DB m Inlines
657660getMediaobject e = do
661+ figTitle <- gets dbFigureTitle
662+ ident <- gets dbFigureId
658663 (imageUrl, attr) <-
659664 case filterChild (named "imageobject") e of
660665 Nothing -> return (mempty, nullAttr)
@@ -667,7 +672,11 @@ getMediaobject e = do
667672 h = case atVal "depth" of
668673 "" -> []
669674 d -> [("height", d)]
670− atr = (atVal "id", T.words $ atVal "role", w ++ h)
675+ id' = case atVal "id" of
676+ x | T.null x -> ident
677+ | otherwise -> x
678+ cs = T.words $ atVal "role"
679+ atr = (id', cs, w ++ h)
671680 in return (atVal "fileref", atr)
672681 let getCaption el = case filterChild (\x -> named "caption" x
673682 || named "textobject" x
@@ -675,7 +684,6 @@ getMediaobject e = do
675684 Nothing -> return mempty
676685 Just z -> mconcat <$>
677686 mapM parseInline (elContent z)
678− figTitle <- gets dbFigureTitle
679687 let (capt, title) = if isNull figTitle
680688 then (getCaption e, "")
681689 else (return figTitle, "fig:")