@@ -89,6 +89,7 @@ import Text.Pandoc.Builder (setMeta, deleteMeta)
8989import Text.Pandoc.Filter (Filter (JSONFilter, LuaFilter), applyFilters)
9090import Text.Pandoc.Highlighting (highlightingStyles)
9191import Text.Pandoc.PDF (makePDF)
92+import Text.Pandoc.Readers.Markdown (yamlToMeta)
9293import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
9394import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
9495 headerShift, isURI, ordNub, safeRead, tabFilter, uriPathToPath)
@@ -399,6 +400,10 @@ convertWithOpts opts = do
399400 ("application/xml", jatsCSL)
400401 return $ ("csl", jatsEncoded) : optMetadata opts
401402 else return $ optMetadata opts
403+ metadataFromFile <-
404+ case optMetadataFile opts of
405+ Nothing -> return mempty
406+ Just file -> readFileLazy file >>= yamlToMeta
402407
403408 case lookup "lang" (optMetadata opts) of
404409 Just l -> case parseBCP47 l of
@@ -491,6 +496,7 @@ convertWithOpts opts = do
491496 ( (if isJust (optExtractMedia opts)
492497 then fillMediaBag
493498 else return)
499+ >=> return . addNonPresentMetadata metadataFromFile
494500 >=> return . addMetadata metadata
495501 >=> applyTransforms transforms
496502 >=> applyFilters readerOpts filters' [format]
@@ -556,6 +562,7 @@ data Opt = Opt
556562 , optTemplate :: Maybe FilePath -- ^ Custom template
557563 , optVariables :: [(String,String)] -- ^ Template variables to set
558564 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
565+ , optMetadataFile :: Maybe FilePath -- ^ Name of YAML metadata file
559566 , optOutputFile :: Maybe FilePath -- ^ Name of output file
560567 , optInputFiles :: [FilePath] -- ^ Names of input files
561568 , optNumberSections :: Bool -- ^ Number sections in LaTeX
@@ -628,6 +635,7 @@ defaultOpts = Opt
628635 , optTemplate = Nothing
629636 , optVariables = []
630637 , optMetadata = []
638+ , optMetadataFile = Nothing
631639 , optOutputFile = Nothing
632640 , optInputFiles = []
633641 , optNumberSections = False
@@ -687,6 +695,9 @@ defaultOpts = Opt
687695 , optStripComments = False
688696 }
689697
698+addNonPresentMetadata :: Text.Pandoc.Meta -> Pandoc -> Pandoc
699+addNonPresentMetadata newmeta (Pandoc meta bs) = Pandoc (meta <> newmeta) bs
700+
690701addMetadata :: [(String, String)] -> Pandoc -> Pandoc
691702addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
692703
@@ -963,6 +974,12 @@ options =
963974 "KEY[:VALUE]")
964975 ""
965976
977+ , Option "" ["metadata-file"]
978+ (ReqArg
979+ (\arg opt -> return opt{ optMetadataFile = Just arg })
980+ "FILE")
981+ ""
982+
966983 , Option "V" ["variable"]
967984 (ReqArg
968985 (\arg opt -> do