Skip to content

Commit

Permalink
JATS reader: parse abstract element into metadata field of same name
Browse files Browse the repository at this point in the history
Closes: jgm#6480
  • Loading branch information
tarleb committed Jun 23, 2020
1 parent 9e6e9a7 commit 4183e3b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Text/Pandoc/Readers/JATS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ parseMetadata e = do
getTitle e
getAuthors e
getAffiliations e
getAbstract e
return mempty

getTitle :: PandocMonad m => Element -> JATS m ()
Expand Down Expand Up @@ -348,6 +349,14 @@ getAffiliations x = do
affs <- mapM getInlines $ filterChildren (named "aff") x
unless (null affs) $ addMeta "institute" affs

getAbstract :: PandocMonad m => Element -> JATS m ()
getAbstract e =
case filterElement (named "abstract") e of
Just s -> do
blks <- getBlocks s
addMeta "abstract" blks
Nothing -> pure ()

getContrib :: PandocMonad m => Element -> JATS m Inlines
getContrib x = do
given <- maybe (return mempty) getInlines
Expand Down
17 changes: 17 additions & 0 deletions test/Tests/Readers/JATS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder

import qualified Data.Text as T

jats :: Text -> Pandoc
jats = purely $ readJATS def

Expand Down Expand Up @@ -126,4 +128,19 @@ tests = [ testGroup "inline code"
\</sec>"
=?> header 1 (image "imgs/foo.jpg" "" mempty)
]

, testGroup "metadata"
[ test jats "abstract" $
T.unlines [ "<front>"
, "<article-meta>"
, "<abstract>"
, "<p>Paragraph 1</p>"
, "<p>Paragraph 2</p>"
, "</abstract>"
, "</article-meta>"
, "</front>"
] =?>
let abstract = para "Paragraph 1" <> para "Paragraph 2"
in setMeta "abstract" abstract $ doc mempty
]
]

0 comments on commit 4183e3b

Please sign in to comment.