git.iko.soy/typeable/pandoc
on master help sign in
Citation related changes.

* Don't look for bibliography in ~/.pandoc. Reason: doing this requires a read + parse of the bibliography even when the document doesn't use citations. This is a big performance drag on regular pandoc invocations. * Only look for default.csl if the document contains references. Reason: avoids the need to read and parse csl file when the document contains no references anyway. * Removed findFirstFile from Shared.

commit3eef887dfa4e47095c4be9b2bdbf67c002e29f90 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 20 Nov 2010, 08:11 (16 years ago) parent46121aa
3 files changed+12−36
src/Text/Pandoc/Biblio.hs+3−2 src/Text/Pandoc/Shared.hs−12 src/pandoc.hs+9−22
src/Text/Pandoc/Biblio.hs+3−2
@@ -38,10 +38,11 @@ import Text.Pandoc.Definition
3838
3939-- | Process a 'Pandoc' document by adding citations formatted
4040-- according to a CSL style, using 'citeproc' from citeproc-hs.
41−processBiblio :: Style -> [Reference] -> Pandoc -> IO Pandoc
42−processBiblio csl r p
41+processBiblio :: FilePath -> [Reference] -> Pandoc -> IO Pandoc
42+processBiblio cslfile r p
4343 = if null r then return p
4444 else do
45+ csl <- readCSLFile cslfile
4546 p' <- processWithM setHash p
4647 let (nts,grps) = if styleClass csl /= "note"
4748 then (,) [] $ queryWith getCitation p'
src/Text/Pandoc/Shared.hs−12
@@ -71,7 +71,6 @@ module Text.Pandoc.Shared (
7171 defaultWriterOptions,
7272 -- * File handling
7373 inDirectory,
74− findFirstFile,
7574 findDataFile,
7675 readDataFile
7776 ) where
@@ -540,17 +539,6 @@ inDirectory path action = do
540539 setCurrentDirectory oldDir
541540 return result
542541
543−-- | Get full file path for the first of a list of files found in the
544−-- specified directory.
545−findFirstFile :: (Maybe FilePath) -> [FilePath] -> IO (Maybe FilePath)
546−findFirstFile Nothing _ = return Nothing
547−findFirstFile (Just _) [] = return Nothing
548−findFirstFile (Just dir) (f:fs) = do
549− ex <- doesFileExist (dir </> f)
550− if ex
551− then return $ Just (dir </> f)
552− else findFirstFile (Just dir) fs
553−
554542-- | Get file path for data file, either from specified user data directory,
555543-- or, if not found there, from Cabal data directory.
556544findDataFile :: Maybe FilePath -> FilePath -> IO FilePath
src/pandoc.hs+9−22
@@ -32,7 +32,7 @@ module Main where
3232import Text.Pandoc
3333import Text.Pandoc.S5 (s5HeaderIncludes)
3434import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
35− headerShift, findDataFile, findFirstFile )
35+ headerShift, findDataFile )
3636#ifdef _HIGHLIGHTING
3737import Text.Pandoc.Highlighting ( languages )
3838#endif
@@ -767,25 +767,6 @@ main = do
767767 return $ ("mathml-script", s) : variables'
768768 _ -> return variables'
769769
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−
789770 let sourceDir = if null sources
790771 then "."
791772 else takeDirectory (head sources)
@@ -803,7 +784,7 @@ main = do
803784 lhsExtension sources,
804785 stateStandalone = standalone',
805786#ifdef _CITEPROC
806− stateCitations = map refId refs',
787+ stateCitations = map refId refs,
807788#endif
808789 stateSmart = smart || writerName' `elem`
809790 ["latex", "context", "latex+lhs", "man"],
@@ -863,7 +844,13 @@ main = do
863844
864845 doc'' <- do
865846#ifdef _CITEPROC
866− processBiblio csl refs' doc'
847+ if null refs
848+ then return doc'
849+ else do
850+ cslfile' <- if null cslfile
851+ then findDataFile datadir "default.csl"
852+ else return cslfile
853+ processBiblio cslfile' refs doc'
867854#else
868855 return doc'
869856#endif