diff options
| -rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 33 | ||||
| -rw-r--r-- | test/docbook-reader.native | 36 | ||||
| -rw-r--r-- | test/docbook-xref.native | 41 |
3 files changed, 74 insertions, 36 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index ea977f9eb..855f1d188 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -541,8 +541,6 @@ data DBState = DBState{ dbSectionLevel :: Int , dbQuoteType :: QuoteType , dbMeta :: Meta , dbBook :: Bool - , dbFigureTitle :: Inlines - , dbFigureId :: Text , dbContent :: [Content] } deriving Show @@ -551,8 +549,6 @@ instance Default DBState where , dbQuoteType = DoubleQuote , dbMeta = mempty , dbBook = False - , dbFigureTitle = mempty - , dbFigureId = mempty , dbContent = [] } @@ -589,11 +585,15 @@ getFigure e = do tit <- case filterChild (named "title") e of Just t -> getInlines t Nothing -> return mempty - let ident = attrValue "id" e - modify $ \st -> st{ dbFigureTitle = tit, dbFigureId = ident } - res <- getBlocks e - modify $ \st -> st{ dbFigureTitle = mempty, dbFigureId = mempty } - return res + contents <- getBlocks e + let contents' = + case toList contents of + [Para [img@Image{}]] -> plain (fromList [img]) + _ -> contents + return $ figureWith + (attrValue "id" e, [], []) + (simpleCaption $ plain tit) + contents' -- convenience function to get an attribute value, defaulting to "" attrValue :: Text -> Element -> Text @@ -803,8 +803,6 @@ addToStart toadd bs = -- A DocBook mediaobject is a wrapper around a set of alternative presentations getMediaobject :: PandocMonad m => Element -> DB m Inlines getMediaobject e = do - figTitle <- gets dbFigureTitle - ident <- gets dbFigureId let (imageUrl, tit, attr) = case filterElements (named "imageobject") e of [] -> (mempty, mempty, nullAttr) @@ -822,23 +820,18 @@ getMediaobject e = do h = case atVal "depth" of "" -> [] d -> [("height", d)] - id' = case atVal "id" of - x | T.null x -> ident - | otherwise -> x + id' = atVal "id" 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 + let capt = case filterChild (\x -> named "caption" x || named "textobject" x - || named "alt" x) el of + || named "alt" x) e of Nothing -> return mempty Just z -> trimInlines . mconcat <$> mapM parseInline (elContent z) - let (capt, title) = if null figTitle - then (getCaption e, tit) - else (return figTitle, "fig:" <> tit) - fmap (imageWith attr imageUrl title) capt + fmap (imageWith attr imageUrl tit) capt getBlocks :: PandocMonad m => Element -> DB m Blocks getBlocks e = mconcat <$> diff --git a/test/docbook-reader.native b/test/docbook-reader.native index 87ccdfac0..8bb313691 100644 --- a/test/docbook-reader.native +++ b/test/docbook-reader.native @@ -1565,11 +1565,37 @@ Pandoc , Space , Str "(1902):" ] - , Para - [ Image - ( "" , [] , [] ) - [ Str "lalune" , Space , Str "fig" , Space , Str "caption" ] - ( "lalune.jpg" , "fig:" ) + , Figure + ( "" , [] , [] ) + (Caption + Nothing + [ Plain + [ Str "lalune" + , Space + , Str "fig" + , Space + , Str "caption" + ] + ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "lalune" + , Space + , Str "alt" + , Space + , Str "text" + , Space + , Str "shadowed" + , Space + , Str "by" + , Space + , Str "fig" + , Space + , Str "caption" + ] + ( "lalune.jpg" , "" ) + ] ] , Para [ Str "Here" diff --git a/test/docbook-xref.native b/test/docbook-xref.native index 9487224ba..8025f698b 100644 --- a/test/docbook-xref.native +++ b/test/docbook-xref.native @@ -228,18 +228,37 @@ Pandoc , Plain [ Str "int1" ] , Plain [ Str "int" ] , Plain [ Str "int2" ] - , Para - [ Image - ( "fig01" , [] , [] ) - [ Str "The" - , Space - , Str "Pythagorean" - , Space - , Str "Theorem" - , Space - , Str "Illustrated" + , Figure + ( "fig01" , [] , [] ) + (Caption + Nothing + [ Plain + [ Str "The" + , Space + , Str "Pythagorean" + , Space + , Str "Theorem" + , Space + , Str "Illustrated" + ] + ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "An" + , Space + , Str "illustration" + , Space + , Str "of" + , Space + , Str "the" + , Space + , Str "Pythagorean" + , Space + , Str "Theorem" + ] + ( "figures/pythag.png" , "" ) ] - ( "figures/pythag.png" , "fig:" ) ] , Table ( "" , [] , [] ) |
