git.iko.soy/typeable/pandoc
on master help sign in
JATS reader: process author metadata.
commit6b63b63f30c8d03575d99f300cca6e54b78d42eb authorJohn MacFarlane <jgm@berkeley.edu> dateSat 23 Dec 2017, 10:03 (9 years ago) parent2c66a42
3 files changed+40−6
src/Text/Pandoc/Readers/JATS.hs+27−5 test/jats-reader.native+1−1 test/jats-reader.xml+12
src/Text/Pandoc/Readers/JATS.hs+27−5
@@ -182,6 +182,7 @@ parseBlock (Elem e) =
182182 "sec" -> gets jatsSectionLevel >>= sect . (+1)
183183 "title" -> return mempty
184184 "title-group" -> checkInMeta getTitle
185+ "contrib-group" -> checkInMeta getAuthors
185186 "graphic" -> para <$> getGraphic e
186187 "journal-meta" -> metaBlock
187188 "article-meta" -> metaBlock
@@ -239,7 +240,28 @@ parseBlock (Elem e) =
239240 Just s -> (text ": " <>) <$>
240241 getInlines s
241242 Nothing -> return mempty
242− addMeta "title" (tit <> subtit)
243+ when (tit /= mempty) $ addMeta "title" tit
244+ when (subtit /= mempty) $ addMeta "subtitle" subtit
245+
246+ getAuthors :: PandocMonad m => JATS m ()
247+ getAuthors = do
248+ authors <- mapM getContrib $ filterChildren
249+ (\x -> named "contrib" x &&
250+ attrValue "contrib-type" x == "author") e
251+ unless (null authors) $ addMeta "author" authors
252+
253+ getContrib :: PandocMonad m => Element -> JATS m Inlines
254+ getContrib x = do
255+ given <- maybe (return mempty) getInlines
256+ $ filterElement (named "given-names") x
257+ family <- maybe (return mempty) getInlines
258+ $ filterElement (named "surname") x
259+ if given == mempty && family == mempty
260+ then return mempty
261+ else if given == mempty || family == mempty
262+ then return $ given <> family
263+ else return $ given <> space <> family
264+ -- TODO institute, etc.
243265
244266 parseTable = do
245267 let isCaption x = named "title" x || named "caption" x
@@ -345,19 +367,19 @@ parseRef e = do
345367 let refPages = refFirstPage <> (if refLastPage == mempty
346368 then mempty
347369 else text "\x2013" <> refLastPage)
348− let personGroups' = filterElements (named "person-group") c
370+ let personGroups' = filterChildren (named "person-group") c
349371 let getName nm = do
350372 given <- maybe (return mempty) getInlines
351− $ filterElement (named "given-names") nm
373+ $ filterChild (named "given-names") nm
352374 family <- maybe (return mempty) getInlines
353− $ filterElement (named "surname") nm
375+ $ filterChild (named "surname") nm
354376 return $ toMetaValue $ Map.fromList [
355377 ("given", given)
356378 , ("family", family)
357379 ]
358380 personGroups <- mapM (\pg ->
359381 do names <- mapM getName
360− (filterElements (named "name") pg)
382+ (filterChildren (named "name") pg)
361383 return (attrValue "person-group-type" pg,
362384 toMetaValue names))
363385 personGroups'
test/jats-reader.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta {unMeta = fromList [("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
1+Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Space,Str "MacFarlane"]]),("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
22[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",SoftBreak,Str "Gruber's",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
33,Header 1 ("headers",[],[]) [Str "Headers"]
44,Header 2 ("level-2-with-an-embedded-link",[],[]) [Str "Level",Space,Str "2",Space,Str "with",Space,Str "an",SoftBreak,Link ("",[],[]) [Str "embedded",SoftBreak,Str "link"] ("/url","")]
test/jats-reader.xml+12
@@ -14,6 +14,18 @@
1414<title-group>
1515<article-title>Pandoc Test Suite</article-title>
1616</title-group>
17+<contrib-group>
18+ <contrib contrib-type="author">
19+ <name>
20+ <surname>MacFarlane</surname>
21+ <given-names>John</given-names>
22+ </name>
23+ <contrib contrib-type="author">
24+ <name>
25+ <surname>Anonymous</surname>
26+ </name>
27+ </contrib>
28+</contrib-group>
1729</article-meta>
1830</front>
1931<body>