diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-01-10 10:25:58 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-01-10 10:28:53 -0800 |
commit | 402d984bc53773e1876000d0d9857b053c002904 (patch) | |
tree | 10c822f302bf776af6ab5ee205b0148594535189 /src/Text/Pandoc | |
parent | c83811773e59d78b45ac5a39d8ac1e4f3c58682d (diff) | |
download | pandoc-402d984bc53773e1876000d0d9857b053c002904.tar.gz |
T.P.Citeproc: factor out getLang.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Citeproc.hs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index bd54ca2bf..e81f93cdd 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -94,9 +94,8 @@ processCitations (Pandoc meta bs) = do case styleRes of Left err -> throwError $ PandocAppError $ prettyCiteprocError err Right style -> return style{ styleAbbreviations = mbAbbrevs } - mblang <- maybe (return Nothing) bcp47LangToIETF - ((lookupMeta "lang" meta <|> lookupMeta "locale" meta) >>= - metaValueToText) + + mblang <- getLang meta let locale = Citeproc.mergeLocales mblang style refs <- getReferences (Just locale) (Pandoc meta bs) @@ -155,6 +154,12 @@ processCitations (Pandoc meta bs) = do $ insertRefs refkvs classes meta'' (walk fixLinks $ B.toList bibs) bs' +-- Retrieve citeproc lang based on metadata. +getLang :: PandocMonad m => Meta -> m (Maybe Lang) +getLang meta = maybe (return Nothing) bcp47LangToIETF + ((lookupMeta "lang" meta <|> lookupMeta "locale" meta) >>= + metaValueToText) + -- | Get references defined inline in the metadata and via an external -- bibliography. Only references that are actually cited in the document -- (either with a genuine citation or with `nocite`) are returned. @@ -162,11 +167,13 @@ processCitations (Pandoc meta bs) = do getReferences :: PandocMonad m => Maybe Locale -> Pandoc -> m [Reference Inlines] getReferences mblocale (Pandoc meta bs) = do - let lang = maybe (Lang "en" (Just "US")) (parseLang . stringify) $ - lookupMeta "lang" meta - let locale = case mblocale of - Just l -> l - Nothing -> either mempty id $ getLocale lang + locale <- case mblocale of + Just l -> return l + Nothing -> do + mblang <- getLang meta + case mblang of + Just lang -> return $ either mempty id $ getLocale lang + Nothing -> return mempty let getCiteId (Cite cs _) = Set.fromList $ map B.citationId cs getCiteId _ = mempty |