@@ -57,7 +57,6 @@ data JATSState = JATSState{ jatsSectionLevel :: Int
57 , jatsQuoteType :: QuoteType
57 , jatsQuoteType :: QuoteType
58 , jatsMeta :: Meta
58 , jatsMeta :: Meta
59 , jatsBook :: Bool
59 , jatsBook :: Bool
60− , jatsFigureTitle :: Inlines
61 , jatsContent :: [Content]
60 , jatsContent :: [Content]
62 } deriving Show
61 } deriving Show
@@ -66,7 +65,6 @@ instance Default JATSState where
66 , jatsQuoteType = DoubleQuote
65 , jatsQuoteType = DoubleQuote
67 , jatsMeta = mempty
66 , jatsMeta = mempty
68 , jatsBook = False
67 , jatsBook = False
69− , jatsFigureTitle = mempty
70 , jatsContent = [] }
68 , jatsContent = [] }
@@ -153,21 +151,18 @@ trimNl = reverse . go . reverse . go
154-- function that is used by both graphic (in parseBlock)
152-- function that is used by both graphic (in parseBlock)
155-- and inline-graphic (in parseInline)
153-- and inline-graphic (in parseInline)
156−getGraphic :: PandocMonad m => Element -> JATS m Inlines
154+getGraphic :: PandocMonad m
155+ => Maybe (Inlines, String) -> Element -> JATS m Inlines
157−getGraphic e = do
156+getGraphic mbfigdata e = do
158 let atVal a = attrValue a e
157 let atVal a = attrValue a e
158+ (ident, title, caption) =
160+ Just (capt, i) -> (i, "fig:" <> atVal "title", capt)
161+ Nothing -> (atVal "id", atVal "title",
162+ text (atVal "alt-text"))
159− attr = (atVal "id", words $ atVal "role", [])
163+ attr = (ident, words $ atVal "role", [])
160 imageUrl = atVal "href"
164 imageUrl = atVal "href"
161− captionOrLabel = case filterChild (\x -> named "caption" x
162− || named "label" x) e of
163− Nothing -> return mempty
164− Just z -> mconcat <$>
165− mapM parseInline (elContent z)
166− figTitle <- gets jatsFigureTitle
167− let (caption, title) = if isNull figTitle
168− then (captionOrLabel, atVal "title")
169− else (return figTitle, "fig:")
170− fmap (imageWith attr imageUrl title) caption
165+ return $ imageWith attr imageUrl title caption
172getBlocks :: PandocMonad m => Element -> JATS m Blocks
167getBlocks :: PandocMonad m => Element -> JATS m Blocks
173getBlocks e = mconcat <$>
168getBlocks e = mconcat <$>
@@ -197,13 +192,13 @@ parseBlock (Elem e) =
197 <$> listitems
192 <$> listitems
198 "def-list" -> definitionList <$> deflistitems
193 "def-list" -> definitionList <$> deflistitems
199 "sec" -> gets jatsSectionLevel >>= sect . (+1)
194 "sec" -> gets jatsSectionLevel >>= sect . (+1)
200− "graphic" -> para <$> getGraphic e
195+ "graphic" -> para <$> getGraphic Nothing e
201 "journal-meta" -> parseMetadata e
196 "journal-meta" -> parseMetadata e
202 "article-meta" -> parseMetadata e
197 "article-meta" -> parseMetadata e
203 "custom-meta" -> parseMetadata e
198 "custom-meta" -> parseMetadata e
204 "title" -> return mempty -- processed by header
199 "title" -> return mempty -- processed by header
205 "table" -> parseTable
200 "table" -> parseTable
206− "fig" -> divWith (attrValue "id" e, ["fig"], []) <$> getBlocks e
201+ "fig" -> parseFigure
207 "table-wrap" -> divWith (attrValue "id" e, ["table-wrap"], []) <$> getBlocks e
202 "table-wrap" -> divWith (attrValue "id" e, ["table-wrap"], []) <$> getBlocks e
208 "caption" -> divWith (attrValue "id" e, ["caption"], []) <$> sect 6
203 "caption" -> divWith (attrValue "id" e, ["caption"], []) <$> sect 6
209 "ref-list" -> parseRefList e
204 "ref-list" -> parseRefList e
@@ -247,6 +242,20 @@ parseBlock (Elem e) =
247 terms' <- mapM getInlines terms
242 terms' <- mapM getInlines terms
248 items' <- mapM getBlocks items
243 items' <- mapM getBlocks items
249 return (mconcat $ intersperse (str "; ") terms', items')
244 return (mconcat $ intersperse (str "; ") terms', items')
246+ -- if a simple caption and single graphic, we emit a standard
247+ -- implicit figure. otherwise, we emit a div with the contents
248+ case filterChildren (named "graphic") e of
250+ caption <- case filterChild (named "caption") e of
252+ intersperse linebreak <$>
254+ (filterChildren (const True) t)
255+ Nothing -> return mempty
256+ img <- getGraphic (Just (caption, attrValue "id" e)) g
258+ _ -> divWith (attrValue "id" e, ["fig"], []) <$> getBlocks e
250 parseTable = do
259 parseTable = do
251 let isCaption x = named "title" x || named "caption" x
260 let isCaption x = named "title" x || named "caption" x
252 caption <- case filterChild isCaption e of
261 caption <- case filterChild isCaption e of
@@ -456,7 +465,7 @@ parseInline (Elem e) =
456 "code" -> codeWithLang
465 "code" -> codeWithLang
457 "monospace" -> codeWithLang
466 "monospace" -> codeWithLang
459− "inline-graphic" -> getGraphic e
468+ "inline-graphic" -> getGraphic Nothing e
460 "disp-quote" -> do
469 "disp-quote" -> do
461 qt <- gets jatsQuoteType
470 qt <- gets jatsQuoteType
462 let qt' = if qt == SingleQuote then DoubleQuote else SingleQuote
471 let qt' = if qt == SingleQuote then DoubleQuote else SingleQuote