aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-10-05 17:23:50 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2020-10-05 17:23:50 -0700
commit89e4f1bf9ad48e3fdefeb5c921e9af62ebc24601 (patch)
tree4dde39d23a8262e99e38b88f44431c0528b9a476 /src/Text
parent4dac62ef3a0377f2c748b348d3c7fa11a1d689f6 (diff)
downloadpandoc-89e4f1bf9ad48e3fdefeb5c921e9af62ebc24601.tar.gz
Improve searching for CSL files...
...and CSL abbreviation files. Use resource path to search in both USERDATADIR/csl and USERDATADIR/csl/dependent. Also, add .csl or .json extension as needed, so you can just do --csl zoology.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Citeproc.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
index feb9be4f1..8274e35d7 100644
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -19,6 +19,7 @@ import Text.Pandoc.Citeproc.CslJson (cslJsonToReferences)
import Text.Pandoc.Citeproc.BibTeX (readBibtexString, Variant(..))
import Text.Pandoc.Citeproc.MetaValue (metaValueToReference, metaValueToText)
import Text.Pandoc.Readers.Markdown (yamlToMeta)
+import Text.Pandoc.Class (setResourcePath, getResourcePath, getUserDataDir)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as L
import Text.Pandoc.Definition as Pandoc
@@ -53,21 +54,29 @@ processCitations (Pandoc meta bs) = do
let cslfile = (lookupMeta "csl" meta <|> lookupMeta "citation-style" meta)
>>= metaValueToText
- let getFile fp = catchError (fst <$> fetchItem fp)
- (\e -> catchError (readDataFile
- (T.unpack $ "csl/" <> fp))
- (\_ -> throwError e))
+ let getFile defaultExtension fp = do
+ oldRp <- getResourcePath
+ mbUdd <- getUserDataDir
+ setResourcePath $ oldRp ++ maybe []
+ (\u -> [u <> "/csl",
+ u <> "/csl/dependent"]) mbUdd
+ let fp' = if T.any (=='.') fp
+ then fp
+ else fp <> defaultExtension
+ (result, _) <- fetchItem fp'
+ setResourcePath oldRp
+ return result
let getCslDefault = readDataFile "default.csl"
- cslContents <- UTF8.toText <$> maybe getCslDefault getFile cslfile
+ cslContents <- UTF8.toText <$> maybe getCslDefault (getFile ".csl") cslfile
let abbrevFile = lookupMeta "citation-abbreviations" meta >>= metaValueToText
mbAbbrevs <- case abbrevFile of
Nothing -> return Nothing
Just fp -> do
- rawAbbr <- getFile fp
+ rawAbbr <- getFile ".json" fp
case eitherDecode (L.fromStrict rawAbbr) of
Left err -> throwError $ PandocCiteprocError $
CiteprocParseError $