JATS reader: parse abstract element into metadata field of same name (#6482)

Closes: #6480
This commit is contained in:
Albert Krewinkel 2020-06-28 19:35:50 +02:00 committed by GitHub
parent d2d5eb8a99
commit 19175af811
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -317,6 +317,7 @@ parseMetadata e = do
getTitle e
getAuthors e
getAffiliations e
getAbstract e
return mempty
getTitle :: PandocMonad m => Element -> JATS m ()
@ -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

View file

@ -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
@ -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
]
]