git.iko.soy/typeable/pandoc
on master help sign in
Citation related changes.
3eef887John MacFarlane
src/Text/Pandoc/Biblio.hs+3−2
@@ -38,10 +38,11 @@ import Text.Pandoc.Definition
38
38
39-- | Process a 'Pandoc' document by adding citations formatted
39-- | Process a 'Pandoc' document by adding citations formatted
40-- according to a CSL style, using 'citeproc' from citeproc-hs.
40-- according to a CSL style, using 'citeproc' from citeproc-hs.
41−processBiblio :: Style -> [Reference] -> Pandoc -> IO Pandoc
41+processBiblio :: FilePath -> [Reference] -> Pandoc -> IO Pandoc
42−processBiblio csl r p
42+processBiblio cslfile r p
43 = if null r then return p
43 = if null r then return p
44 else do
44 else do
45+ csl <- readCSLFile cslfile
45 p' <- processWithM setHash p
46 p' <- processWithM setHash p
46 let (nts,grps) = if styleClass csl /= "note"
47 let (nts,grps) = if styleClass csl /= "note"
47 then (,) [] $ queryWith getCitation p'
48 then (,) [] $ queryWith getCitation p'
src/Text/Pandoc/Shared.hs−12
@@ -71,7 +71,6 @@ module Text.Pandoc.Shared (
71 defaultWriterOptions,
71 defaultWriterOptions,
72 -- * File handling
72 -- * File handling
73 inDirectory,
73 inDirectory,
74− findFirstFile,
75 findDataFile,
74 findDataFile,
76 readDataFile
75 readDataFile
77 ) where
76 ) where
@@ -540,17 +539,6 @@ inDirectory path action = do
540 setCurrentDirectory oldDir
539 setCurrentDirectory oldDir
541 return result
540 return result
542
541
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−
554-- | Get file path for data file, either from specified user data directory,
542-- | Get file path for data file, either from specified user data directory,
555-- or, if not found there, from Cabal data directory.
543-- or, if not found there, from Cabal data directory.
556findDataFile :: Maybe FilePath -> FilePath -> IO FilePath
544findDataFile :: Maybe FilePath -> FilePath -> IO FilePath
src/pandoc.hs+9−22
@@ -32,7 +32,7 @@ module Main where
32import Text.Pandoc
32import Text.Pandoc
33import Text.Pandoc.S5 (s5HeaderIncludes)
33import Text.Pandoc.S5 (s5HeaderIncludes)
34import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
34import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
35− headerShift, findDataFile, findFirstFile )
35+ headerShift, findDataFile )
36#ifdef _HIGHLIGHTING
36#ifdef _HIGHLIGHTING
37import Text.Pandoc.Highlighting ( languages )
37import Text.Pandoc.Highlighting ( languages )
38#endif
38#endif
@@ -767,25 +767,6 @@ main = do
767 return $ ("mathml-script", s) : variables'
767 return $ ("mathml-script", s) : variables'
768 _ -> return variables'
768 _ -> return variables'
769
769
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−
789 let sourceDir = if null sources
770 let sourceDir = if null sources
790 then "."
771 then "."
791 else takeDirectory (head sources)
772 else takeDirectory (head sources)
@@ -803,7 +784,7 @@ main = do
803 lhsExtension sources,
784 lhsExtension sources,
804 stateStandalone = standalone',
785 stateStandalone = standalone',
805#ifdef _CITEPROC
786#ifdef _CITEPROC
806− stateCitations = map refId refs',
787+ stateCitations = map refId refs,
807#endif
788#endif
808 stateSmart = smart || writerName' `elem`
789 stateSmart = smart || writerName' `elem`
809 ["latex", "context", "latex+lhs", "man"],
790 ["latex", "context", "latex+lhs", "man"],
@@ -863,7 +844,13 @@ main = do
863
844
864 doc'' <- do
845 doc'' <- do
865#ifdef _CITEPROC
846#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'
867#else
854#else
868 return doc'
855 return doc'
869#endif
856#endif