git.iko.soy/typeable/pandoc
on master help sign in
Use default biblio.{xml,json,bib} in pandoc data dir if none specified.
commit46121aa2e1ad9afd8b06684fa9a36a00a73c106d authorJohn MacFarlane <jgm@berkeley.edu> dateFri 19 Nov 2010, 22:14 (16 years ago) parent9cb0581
1 file changed+23−21
src/pandoc.hs+23−21
src/pandoc.hs+23−21
@@ -32,7 +32,7 @@ module Main where
3232import Text.Pandoc
3333import Text.Pandoc.S5 (s5HeaderIncludes)
3434import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
35− headerShift )
35+ headerShift, findDataFile, findFirstFile )
3636#ifdef _HIGHLIGHTING
3737import Text.Pandoc.Highlighting ( languages )
3838#endif
@@ -42,7 +42,7 @@ import System.FilePath
4242import System.Console.GetOpt
4343import Data.Char ( toLower, isDigit )
4444import Data.List ( intercalate, isSuffixOf )
45−import System.Directory ( getAppUserDataDirectory, doesFileExist )
45+import System.Directory ( getAppUserDataDirectory )
4646import System.IO ( stdout, stderr )
4747import qualified Text.Pandoc.UTF8 as UTF8
4848#ifdef _CITEPROC
@@ -55,7 +55,6 @@ import Network.URI (parseURI, isURI, URI(..))
5555import qualified Data.ByteString.Lazy as B
5656import Data.ByteString.Lazy.UTF8 (toString, fromString)
5757import Codec.Binary.UTF8.String (decodeString, encodeString)
58−import Paths_pandoc (getDataFileName)
5958
6059copyrightMessage :: String
6160copyrightMessage = "\nCopyright (C) 2006-2010 John MacFarlane\n" ++
@@ -768,6 +767,25 @@ main = do
768767 return $ ("mathml-script", s) : variables'
769768 _ -> return variables'
770769
770+#ifdef _CITEPROC
771+ cslfile' <- if null cslfile
772+ then findDataFile datadir "default.csl"
773+ else return cslfile
774+ csl <- readCSLFile cslfile'
775+ refs' <- if null refs
776+ then do
777+ f <- findFirstFile datadir
778+ ["biblio.xml","biblio.json","biblio.bib"]
779+ case f of
780+ Just x -> catch (readBiblioFile x) $ \e -> do
781+ UTF8.hPutStrLn stderr $
782+ "Error reading bibliography `" ++ x ++ "'"
783+ UTF8.hPutStrLn stderr $ show e
784+ exitWith (ExitFailure 23) >> return []
785+ Nothing -> return []
786+ else return refs
787+#endif
788+
771789 let sourceDir = if null sources
772790 then "."
773791 else takeDirectory (head sources)
@@ -785,7 +803,7 @@ main = do
785803 lhsExtension sources,
786804 stateStandalone = standalone',
787805#ifdef _CITEPROC
788− stateCitations = map refId refs,
806+ stateCitations = map refId refs',
789807#endif
790808 stateSmart = smart || writerName' `elem`
791809 ["latex", "context", "latex+lhs", "man"],
@@ -839,29 +857,13 @@ main = do
839857
840858 let convertTabs = tabFilter (if preserveTabs then 0 else tabStop)
841859
842−#ifdef _CITEPROC
843− cslfile' <- if null cslfile
844− then do
845− let defaultcsl = "default.csl"
846− csldatafile <- getDataFileName defaultcsl
847− case datadir of
848− Nothing -> return csldatafile
849− Just u -> do
850− ex <- doesFileExist $ u </> defaultcsl
851− if ex
852− then return $ u </> defaultcsl
853− else return csldatafile
854− else return cslfile
855− csl <- readCSLFile cslfile'
856−#endif
857−
858860 doc <- fmap (reader startParserState . convertTabs . intercalate "\n") (readSources sources)
859861
860862 let doc' = foldr ($) doc transforms
861863
862864 doc'' <- do
863865#ifdef _CITEPROC
864− processBiblio csl refs doc'
866+ processBiblio csl refs' doc'
865867#else
866868 return doc'
867869#endif