mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-01 15:38:09 +08:00
DocBook reader: parse figure as a Figure element in the AST.
Closes #8668.
This commit is contained in:
@@ -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 <$>
|
||||
|
||||
@@ -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"
|
||||
|
||||
+30
-11
@@ -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
|
||||
( "" , [] , [] )
|
||||
|
||||
Reference in New Issue
Block a user