summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-03-05 12:44:44 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2023-03-05 12:44:44 -0800
commit118dd922326f25a7d95b2bd120216a8c6268188b (patch)
treec47ed7dfef581718d7d8cea30c6cdc8ae6acdb16 /src
parent2dd645e26e57cfc7944f68276c7e01de989fef20 (diff)
JATS reader: avoid generating duplicate figure captions.
Closes #8669.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/JATS.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/JATS.hs b/src/Text/Pandoc/Readers/JATS.hs
index fbf46a339..47cd596e8 100644
--- a/src/Text/Pandoc/Readers/JATS.hs
+++ b/src/Text/Pandoc/Readers/JATS.hs
@@ -47,6 +47,7 @@ data JATSState = JATSState{ jatsSectionLevel :: Int
, jatsBook :: Bool
, jatsFootnotes :: Map.Map Text Blocks
, jatsContent :: [Content]
+ , jatsInFigure :: Bool
} deriving Show
instance Default JATSState where
@@ -55,7 +56,8 @@ instance Default JATSState where
, jatsMeta = mempty
, jatsBook = False
, jatsFootnotes = mempty
- , jatsContent = [] }
+ , jatsContent = []
+ , jatsInFigure = False }
readJATS :: (PandocMonad m, ToSources a)
@@ -188,7 +190,11 @@ parseBlock (Elem e) =
<$> getBlocks e
"table-wrap" -> divWith (attrValue "id" e, ["table-wrap"], [])
<$> getBlocks e
- "caption" -> divWith (attrValue "id" e, ["caption"], []) <$> sect 6
+ "caption" -> do
+ inFigure <- gets jatsInFigure
+ if inFigure -- handled by parseFigure
+ then return mempty
+ else divWith (attrValue "id" e, ["caption"], []) <$> sect 6
"fn-group" -> parseFootnoteGroup
"ref-list" -> parseRefList e
"?xml" -> return mempty
@@ -232,12 +238,13 @@ parseBlock (Elem e) =
items' <- mapM getBlocks items
return (mconcat $ intersperse (str "; ") terms', items')
parseFigure = do
+ modify $ \st -> st{ jatsInFigure = True }
capt <- case filterChild (named "caption") e of
Just t -> mconcat . intersperse linebreak <$>
mapM getInlines (filterChildren (const True) t)
Nothing -> return mempty
contents <- getBlocks e
-
+ modify $ \st -> st{ jatsInFigure = False }
return $ figureWith
(attrValue "id" e, [], [])
(simpleCaption $ plain capt)