@@ -89,6 +89,7 @@ import Text.Pandoc.Builder (setMeta, deleteMeta)
89import Text.Pandoc.Filter (Filter (JSONFilter, LuaFilter), applyFilters)
89import Text.Pandoc.Filter (Filter (JSONFilter, LuaFilter), applyFilters)
90import Text.Pandoc.Highlighting (highlightingStyles)
90import Text.Pandoc.Highlighting (highlightingStyles)
91import Text.Pandoc.PDF (makePDF)
91import Text.Pandoc.PDF (makePDF)
92+import Text.Pandoc.Readers.Markdown (yamlToMeta)
92import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
93import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
93import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
94import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
94 headerShift, isURI, ordNub, safeRead, tabFilter, uriPathToPath)
95 headerShift, isURI, ordNub, safeRead, tabFilter, uriPathToPath)
@@ -399,6 +400,10 @@ convertWithOpts opts = do
399 ("application/xml", jatsCSL)
400 ("application/xml", jatsCSL)
400 return $ ("csl", jatsEncoded) : optMetadata opts
401 return $ ("csl", jatsEncoded) : optMetadata opts
401 else return $ optMetadata opts
402 else return $ optMetadata opts
404+ case optMetadataFile opts of
405+ Nothing -> return mempty
406+ Just file -> readFileLazy file >>= yamlToMeta
403 case lookup "lang" (optMetadata opts) of
408 case lookup "lang" (optMetadata opts) of
404 Just l -> case parseBCP47 l of
409 Just l -> case parseBCP47 l of
@@ -491,6 +496,7 @@ convertWithOpts opts = do
491 ( (if isJust (optExtractMedia opts)
496 ( (if isJust (optExtractMedia opts)
492 then fillMediaBag
497 then fillMediaBag
493 else return)
498 else return)
499+ >=> return . addNonPresentMetadata metadataFromFile
494 >=> return . addMetadata metadata
500 >=> return . addMetadata metadata
495 >=> applyTransforms transforms
501 >=> applyTransforms transforms
496 >=> applyFilters readerOpts filters' [format]
502 >=> applyFilters readerOpts filters' [format]
@@ -556,6 +562,7 @@ data Opt = Opt
556 , optTemplate :: Maybe FilePath -- ^ Custom template
562 , optTemplate :: Maybe FilePath -- ^ Custom template
557 , optVariables :: [(String,String)] -- ^ Template variables to set
563 , optVariables :: [(String,String)] -- ^ Template variables to set
558 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
564 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
565+ , optMetadataFile :: Maybe FilePath -- ^ Name of YAML metadata file
559 , optOutputFile :: Maybe FilePath -- ^ Name of output file
566 , optOutputFile :: Maybe FilePath -- ^ Name of output file
560 , optInputFiles :: [FilePath] -- ^ Names of input files
567 , optInputFiles :: [FilePath] -- ^ Names of input files
561 , optNumberSections :: Bool -- ^ Number sections in LaTeX
568 , optNumberSections :: Bool -- ^ Number sections in LaTeX
@@ -628,6 +635,7 @@ defaultOpts = Opt
628 , optTemplate = Nothing
635 , optTemplate = Nothing
629 , optVariables = []
636 , optVariables = []
630 , optMetadata = []
637 , optMetadata = []
638+ , optMetadataFile = Nothing
631 , optOutputFile = Nothing
639 , optOutputFile = Nothing
632 , optInputFiles = []
640 , optInputFiles = []
633 , optNumberSections = False
641 , optNumberSections = False
@@ -687,6 +695,9 @@ defaultOpts = Opt
687 , optStripComments = False
695 , optStripComments = False
698+addNonPresentMetadata :: Text.Pandoc.Meta -> Pandoc -> Pandoc
699+addNonPresentMetadata newmeta (Pandoc meta bs) = Pandoc (meta <> newmeta) bs
690addMetadata :: [(String, String)] -> Pandoc -> Pandoc
701addMetadata :: [(String, String)] -> Pandoc -> Pandoc
691addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
702addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
@@ -963,6 +974,12 @@ options =
963 "KEY[:VALUE]")
974 "KEY[:VALUE]")
977+ , Option "" ["metadata-file"]
979+ (\arg opt -> return opt{ optMetadataFile = Just arg })
966 , Option "V" ["variable"]
983 , Option "V" ["variable"]
968 (\arg opt -> do
985 (\arg opt -> do