mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 17:20:47 +08:00
JATS reader: parse abstract element into metadata field of same name (#6482)
Closes: #6480
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user