git.iko.soy/typeable/pandoc
on master help sign in
T.P.Citeproc: factor out getLang.
commit402d984bc53773e1876000d0d9857b053c002904 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 10 Jan 2021, 10:25 (6 years ago) parentc838117
1 file changed+15−8
src/Text/Pandoc/Citeproc.hs+15−8
src/Text/Pandoc/Citeproc.hs+15−8
@@ -94,9 +94,8 @@ processCitations (Pandoc meta bs) = do
9494 case styleRes of
9595 Left err -> throwError $ PandocAppError $ prettyCiteprocError err
9696 Right style -> return style{ styleAbbreviations = mbAbbrevs }
97− mblang <- maybe (return Nothing) bcp47LangToIETF
98− ((lookupMeta "lang" meta <|> lookupMeta "locale" meta) >>=
99− metaValueToText)
97+
98+ mblang <- getLang meta
10099 let locale = Citeproc.mergeLocales mblang style
101100
102101 refs <- getReferences (Just locale) (Pandoc meta bs)
@@ -155,6 +154,12 @@ processCitations (Pandoc meta bs) = do
155154 $ insertRefs refkvs classes meta''
156155 (walk fixLinks $ B.toList bibs) bs'
157156
157+-- Retrieve citeproc lang based on metadata.
158+getLang :: PandocMonad m => Meta -> m (Maybe Lang)
159+getLang meta = maybe (return Nothing) bcp47LangToIETF
160+ ((lookupMeta "lang" meta <|> lookupMeta "locale" meta) >>=
161+ metaValueToText)
162+
158163-- | Get references defined inline in the metadata and via an external
159164-- bibliography. Only references that are actually cited in the document
160165-- (either with a genuine citation or with `nocite`) are returned.
@@ -162,11 +167,13 @@ processCitations (Pandoc meta bs) = do
162167getReferences :: PandocMonad m
163168 => Maybe Locale -> Pandoc -> m [Reference Inlines]
164169getReferences mblocale (Pandoc meta bs) = do
165− let lang = maybe (Lang "en" (Just "US")) (parseLang . stringify) $
166− lookupMeta "lang" meta
167− let locale = case mblocale of
168− Just l -> l
169− Nothing -> either mempty id $ getLocale lang
170+ locale <- case mblocale of
171+ Just l -> return l
172+ Nothing -> do
173+ mblang <- getLang meta
174+ case mblang of
175+ Just lang -> return $ either mempty id $ getLocale lang
176+ Nothing -> return mempty
170177
171178 let getCiteId (Cite cs _) = Set.fromList $ map B.citationId cs
172179 getCiteId _ = mempty