@@ -50,7 +50,7 @@ import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), defaultOpts)
5050import Text.Pandoc.App.CommandLineOptions (parseOptions, options)
5151import Text.Pandoc.App.OutputSettings (OutputSettings (..), optToOutputSettings)
5252import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
53−import Text.Pandoc.Builder (setMeta, deleteMeta)
53+import Text.Pandoc.Builder (setMeta)
5454import Text.Pandoc.Filter (Filter (JSONFilter, LuaFilter), applyFilters)
5555import Text.Pandoc.PDF (makePDF)
5656import Text.Pandoc.Readers.Markdown (yamlToMeta)
@@ -58,6 +58,7 @@ import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
5858import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
5959 headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput,
6060 defaultUserDataDirs)
61+import Text.Pandoc.Writers.Shared (lookupMetaString)
6162import qualified Text.Pandoc.UTF8 as UTF8
6263#ifndef _WINDOWS
6364import System.Posix.IO (stdOutput)
@@ -79,7 +80,8 @@ convertWithOpts opts = do
7980 let isPandocCiteproc (JSONFilter f) = takeBaseName f == "pandoc-citeproc"
8081 isPandocCiteproc _ = False
8182 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
82− let needsCiteproc = isJust (lookup "bibliography" (optMetadata opts)) &&
83+ let needsCiteproc = isJust (lookupMeta "bibliography"
84+ (optMetadata opts)) &&
8385 optCiteMethod opts `notElem` [Natbib, Biblatex] &&
8486 all (not . isPandocCiteproc) filters
8587 let filters' = if needsCiteproc then JSONFilter "pandoc-citeproc" : filters
@@ -195,20 +197,21 @@ convertWithOpts opts = do
195197 Just f -> UTF8.toString <$> readFileStrict f
196198
197199 metadata <- if format == "jats" &&
198− isNothing (lookup "csl" (optMetadata opts)) &&
199− isNothing (lookup "citation-style" (optMetadata opts))
200+ isNothing (lookupMeta "csl" (optMetadata opts)) &&
201+ isNothing (lookupMeta "citation-style"
202+ (optMetadata opts))
200203 then do
201204 jatsCSL <- readDataFile "jats.csl"
202205 let jatsEncoded = makeDataURI
203206 ("application/xml", jatsCSL)
204− return $ ("csl", jatsEncoded) : optMetadata opts
207+ return $ setMeta "csl" jatsEncoded $ optMetadata opts
205208 else return $ optMetadata opts
206209
207− case lookup "lang" (optMetadata opts) of
208− Just l -> case parseBCP47 l of
209− Left _ -> return ()
210+ case lookupMetaString "lang" (optMetadata opts) of
211+ "" -> setTranslations $ Lang "en" "" "US" []
212+ l -> case parseBCP47 l of
213+ Left _ -> report $ InvalidLang l
210214 Right l' -> setTranslations l'
211− Nothing -> setTranslations $ Lang "en" "" "US" []
212215
213216 let readerOpts = def{
214217 readerStandalone = standalone
@@ -279,8 +282,8 @@ convertWithOpts opts = do
279282 ( (if isJust (optExtractMedia opts)
280283 then fillMediaBag
281284 else return)
282− >=> return . addNonPresentMetadata metadataFromFile
283− >=> return . addMetadata metadata
285+ >=> return . adjustMetadata (<> metadataFromFile)
286+ >=> return . adjustMetadata (metadata <>)
284287 >=> applyTransforms transforms
285288 >=> applyFilters readerOpts filters' [format]
286289 >=> maybe return extractMedia (optExtractMedia opts)
@@ -319,33 +322,8 @@ htmlFormat = (`elem` ["html","html4","html5","s5","slidy",
319322isTextFormat :: String -> Bool
320323isTextFormat s = s `notElem` ["odt","docx","epub2","epub3","epub","pptx"]
321324
322−addNonPresentMetadata :: Text.Pandoc.Meta -> Pandoc -> Pandoc
323−addNonPresentMetadata newmeta (Pandoc meta bs) = Pandoc (meta <> newmeta) bs
324−
325−addMetadata :: [(String, String)] -> Pandoc -> Pandoc
326−addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
327−
328−addMeta :: (String, String) -> Pandoc -> Pandoc
329−addMeta (k, v) (Pandoc meta bs) = Pandoc meta' bs
330− where meta' = case lookupMeta k meta of
331− Nothing -> setMeta k v' meta
332− Just (MetaList xs) ->
333− setMeta k (MetaList (xs ++ [v'])) meta
334− Just x -> setMeta k (MetaList [x, v']) meta
335− v' = readMetaValue v
336−
337−removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc
338−removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs
339−
340−readMetaValue :: String -> MetaValue
341−readMetaValue s
342− | s == "true" = MetaBool True
343− | s == "True" = MetaBool True
344− | s == "TRUE" = MetaBool True
345− | s == "false" = MetaBool False
346− | s == "False" = MetaBool False
347− | s == "FALSE" = MetaBool False
348− | otherwise = MetaString s
325+adjustMetadata :: (Meta -> Meta) -> Pandoc -> Pandoc
326+adjustMetadata f (Pandoc meta bs) = Pandoc (f meta) bs
349327
350328-- Transformations of a Pandoc document post-parsing:
351329