From 87033b285669901505f6da8b2969911a29c448fd Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 15 Dec 2020 09:09:51 -0800 Subject: Use fetchItem to get external bibliography. This means that: - a URL may be provided, and pandoc will fetch the resource. - Pandoc will search the resource path for the bibliography if it is not found relative to the working directory. Closes #6940. --- src/Text/Pandoc/Citeproc.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index 82d1dc32f..770d571a6 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -190,24 +190,23 @@ insertSpace ils = getRefsFromBib :: PandocMonad m => Locale -> (Text -> Bool) -> Text -> m [Reference Inlines] -getRefsFromBib locale idpred t = do - let fp = T.unpack t - raw <- readFileStrict fp - case formatFromExtension fp of +getRefsFromBib locale idpred fp = do + (raw, _) <- fetchItem fp + case formatFromExtension (T.unpack fp) of Just f -> getRefs locale f idpred (Just fp) raw Nothing -> throwError $ PandocAppError $ - "Could not determine bibliography format for " <> t + "Could not determine bibliography format for " <> fp getRefs :: PandocMonad m => Locale -> BibFormat -> (Text -> Bool) - -> Maybe FilePath + -> Maybe Text -> ByteString -> m [Reference Inlines] getRefs locale format idpred mbfp raw = do let err' = throwError . - PandocBibliographyError (maybe mempty T.pack mbfp) + PandocBibliographyError (fromMaybe mempty mbfp) case format of Format_bibtex -> either (err' . tshow) return . @@ -222,7 +221,7 @@ getRefs locale format idpred mbfp raw = do Format_yaml -> do rs <- yamlToRefs idpred def{ readerExtensions = pandocExtensions } - mbfp + (T.unpack <$> mbfp) (L.fromStrict raw) return $ mapMaybe metaValueToReference rs -- cgit v1.2.3