aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/JATS.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-23 10:03:13 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-23 10:03:13 -0800
commit6b63b63f30c8d03575d99f300cca6e54b78d42eb (patch)
tree4c1dccf09f4500ed50f42df0986c29ca8809aabb /src/Text/Pandoc/Readers/JATS.hs
parent2c66a42ab81d40e771eda0f054c62f22ad45f3d0 (diff)
downloadpandoc-6b63b63f30c8d03575d99f300cca6e54b78d42eb.tar.gz
JATS reader: process author metadata.
Diffstat (limited to 'src/Text/Pandoc/Readers/JATS.hs')
-rw-r--r--src/Text/Pandoc/Readers/JATS.hs32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/JATS.hs b/src/Text/Pandoc/Readers/JATS.hs
index 8c0cb2db5..29c443d86 100644
--- a/src/Text/Pandoc/Readers/JATS.hs
+++ b/src/Text/Pandoc/Readers/JATS.hs
@@ -182,6 +182,7 @@ parseBlock (Elem e) =
"sec" -> gets jatsSectionLevel >>= sect . (+1)
"title" -> return mempty
"title-group" -> checkInMeta getTitle
+ "contrib-group" -> checkInMeta getAuthors
"graphic" -> para <$> getGraphic e
"journal-meta" -> metaBlock
"article-meta" -> metaBlock
@@ -239,7 +240,28 @@ parseBlock (Elem e) =
Just s -> (text ": " <>) <$>
getInlines s
Nothing -> return mempty
- addMeta "title" (tit <> subtit)
+ when (tit /= mempty) $ addMeta "title" tit
+ when (subtit /= mempty) $ addMeta "subtitle" subtit
+
+ getAuthors :: PandocMonad m => JATS m ()
+ getAuthors = do
+ authors <- mapM getContrib $ filterChildren
+ (\x -> named "contrib" x &&
+ attrValue "contrib-type" x == "author") e
+ unless (null authors) $ addMeta "author" authors
+
+ getContrib :: PandocMonad m => Element -> JATS m Inlines
+ getContrib x = do
+ given <- maybe (return mempty) getInlines
+ $ filterElement (named "given-names") x
+ family <- maybe (return mempty) getInlines
+ $ filterElement (named "surname") x
+ if given == mempty && family == mempty
+ then return mempty
+ else if given == mempty || family == mempty
+ then return $ given <> family
+ else return $ given <> space <> family
+ -- TODO institute, etc.
parseTable = do
let isCaption x = named "title" x || named "caption" x
@@ -345,19 +367,19 @@ parseRef e = do
let refPages = refFirstPage <> (if refLastPage == mempty
then mempty
else text "\x2013" <> refLastPage)
- let personGroups' = filterElements (named "person-group") c
+ let personGroups' = filterChildren (named "person-group") c
let getName nm = do
given <- maybe (return mempty) getInlines
- $ filterElement (named "given-names") nm
+ $ filterChild (named "given-names") nm
family <- maybe (return mempty) getInlines
- $ filterElement (named "surname") nm
+ $ filterChild (named "surname") nm
return $ toMetaValue $ Map.fromList [
("given", given)
, ("family", family)
]
personGroups <- mapM (\pg ->
do names <- mapM getName
- (filterElements (named "name") pg)
+ (filterChildren (named "name") pg)
return (attrValue "person-group-type" pg,
toMetaValue names))
personGroups'