@@ -521,6 +521,7 @@ data DBState = DBState{ dbSectionLevel :: Int
521 , dbMeta :: Meta
521 , dbMeta :: Meta
522 , dbBook :: Bool
522 , dbBook :: Bool
523 , dbFigureTitle :: Inlines
523 , dbFigureTitle :: Inlines
524+ , dbFigureId :: Text
524 , dbContent :: [Content]
525 , dbContent :: [Content]
525 } deriving Show
526 } deriving Show
@@ -530,6 +531,7 @@ instance Default DBState where
530 , dbMeta = mempty
531 , dbMeta = mempty
531 , dbBook = False
532 , dbBook = False
532 , dbFigureTitle = mempty
533 , dbFigureTitle = mempty
534+ , dbFigureId = mempty
533 , dbContent = [] }
535 , dbContent = [] }
@@ -557,9 +559,10 @@ getFigure e = do
557 tit <- case filterChild (named "title") e of
559 tit <- case filterChild (named "title") e of
558 Just t -> getInlines t
560 Just t -> getInlines t
559 Nothing -> return mempty
561 Nothing -> return mempty
562+ let ident = attrValue "id" e
560− modify $ \st -> st{ dbFigureTitle = tit }
563+ modify $ \st -> st{ dbFigureTitle = tit, dbFigureId = ident }
561 res <- getBlocks e
564 res <- getBlocks e
562− modify $ \st -> st{ dbFigureTitle = mempty }
565+ modify $ \st -> st{ dbFigureTitle = mempty, dbFigureId = mempty }
563 return res
566 return res
565-- normalize input, consolidating adjacent Text and CRef elements
568-- normalize input, consolidating adjacent Text and CRef elements
@@ -655,6 +658,8 @@ addToStart toadd bs =
655-- A DocBook mediaobject is a wrapper around a set of alternative presentations
658-- A DocBook mediaobject is a wrapper around a set of alternative presentations
656getMediaobject :: PandocMonad m => Element -> DB m Inlines
659getMediaobject :: PandocMonad m => Element -> DB m Inlines
657getMediaobject e = do
660getMediaobject e = do
661+ figTitle <- gets dbFigureTitle
662+ ident <- gets dbFigureId
658 (imageUrl, attr) <-
663 (imageUrl, attr) <-
659 case filterChild (named "imageobject") e of
664 case filterChild (named "imageobject") e of
660 Nothing -> return (mempty, nullAttr)
665 Nothing -> return (mempty, nullAttr)
@@ -667,7 +672,11 @@ getMediaobject e = do
667 h = case atVal "depth" of
672 h = case atVal "depth" of
669 d -> [("height", d)]
674 d -> [("height", d)]
675+ id' = case atVal "id" of
676+ x | T.null x -> ident
670− atr = (atVal "id", T.words $ atVal "role", w ++ h)
678+ cs = T.words $ atVal "role"
679+ atr = (id', cs, w ++ h)
671 in return (atVal "fileref", atr)
680 in return (atVal "fileref", atr)
672 let getCaption el = case filterChild (\x -> named "caption" x
681 let getCaption el = case filterChild (\x -> named "caption" x
673 || named "textobject" x
682 || named "textobject" x
@@ -675,7 +684,6 @@ getMediaobject e = do
675 Nothing -> return mempty
684 Nothing -> return mempty
676 Just z -> mconcat <$>
685 Just z -> mconcat <$>
677 mapM parseInline (elContent z)
686 mapM parseInline (elContent z)
678− figTitle <- gets dbFigureTitle
679 let (capt, title) = if isNull figTitle
687 let (capt, title) = if isNull figTitle
680 then (getCaption e, "")
688 then (getCaption e, "")
681 else (return figTitle, "fig:")
689 else (return figTitle, "fig:")