aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-11-18 14:15:26 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-11-18 14:15:26 -0800
commitbbb60a2586f29785fd9ba592770bc2f7842deba4 (patch)
tree6db08b5683352116a6ae033cc8fc58014ddd4a00 /src
parent482b4b8d738aab1e0fed7ad1bb4702c567438dde (diff)
downloadpandoc-bbb60a2586f29785fd9ba592770bc2f7842deba4.tar.gz
If --csl not specified, read from data files or default.
Thus --csl behaves like --reference-odt, --template, etc.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Biblio.hs7
-rw-r--r--src/pandoc.hs29
2 files changed, 25 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs
index dde822da8..12911e1ee 100644
--- a/src/Text/Pandoc/Biblio.hs
+++ b/src/Text/Pandoc/Biblio.hs
@@ -29,7 +29,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
module Text.Pandoc.Biblio ( processBiblio ) where
-import Control.Monad ( when )
import Data.List
import Data.Unique
import qualified Data.Map as M
@@ -39,12 +38,10 @@ import Text.Pandoc.Definition
-- | Process a 'Pandoc' document by adding citations formatted
-- according to a CSL style, using 'citeproc' from citeproc-hs.
-processBiblio :: String -> [Reference] -> Pandoc -> IO Pandoc
-processBiblio cf r p
+processBiblio :: Style -> [Reference] -> Pandoc -> IO Pandoc
+processBiblio csl r p
= if null r then return p
else do
- when (null cf) $ error "Missing the needed citation style file"
- csl <- readCSLFile cf
p' <- processWithM setHash p
let (nts,grps) = if styleClass csl /= "note"
then (,) [] $ queryWith getCitation p'
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 5fcec5005..7822a0b67 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -42,7 +42,7 @@ import System.FilePath
import System.Console.GetOpt
import Data.Char ( toLower, isDigit )
import Data.List ( intercalate, isSuffixOf )
-import System.Directory ( getAppUserDataDirectory )
+import System.Directory ( getAppUserDataDirectory, doesFileExist )
import System.IO ( stdout, stderr )
import qualified Text.Pandoc.UTF8 as UTF8
#ifdef _CITEPROC
@@ -55,6 +55,7 @@ import Network.URI (parseURI, isURI, URI(..))
import qualified Data.ByteString.Lazy as B
import Data.ByteString.Lazy.UTF8 (toString, fromString)
import Codec.Binary.UTF8.String (decodeString, encodeString)
+import Paths_pandoc (getDataFileName)
copyrightMessage :: String
copyrightMessage = "\nCopyright (C) 2006-2010 John MacFarlane\n" ++
@@ -164,7 +165,7 @@ data Opt = Opt
, optDataDir :: Maybe FilePath
#ifdef _CITEPROC
, optBibliography :: [Reference]
- , optCslFile :: String
+ , optCslFile :: FilePath
#endif
}
@@ -205,7 +206,7 @@ defaultOpts = Opt
, optDataDir = Nothing
#ifdef _CITEPROC
, optBibliography = []
- , optCslFile = []
+ , optCslFile = ""
#endif
}
@@ -532,7 +533,7 @@ options =
""
, Option "" ["csl"]
(ReqArg
- (\arg opt -> return opt { optCslFile = arg} )
+ (\arg opt -> return opt { optCslFile = arg })
"FILENAME")
""
#endif
@@ -685,7 +686,7 @@ main = do
, optDataDir = mbDataDir
#ifdef _CITEPROC
, optBibliography = refs
- , optCslFile = cslFile
+ , optCslFile = cslfile
#endif
} = opts
@@ -838,13 +839,29 @@ main = do
let convertTabs = tabFilter (if preserveTabs then 0 else tabStop)
+#ifdef _CITEPROC
+ cslfile' <- if null cslfile
+ then do
+ let defaultcsl = "default.csl"
+ csldatafile <- getDataFileName defaultcsl
+ case datadir of
+ Nothing -> return csldatafile
+ Just u -> do
+ ex <- doesFileExist $ u </> defaultcsl
+ if ex
+ then return $ u </> defaultcsl
+ else return csldatafile
+ else return cslfile
+ csl <- readCSLFile cslfile'
+#endif
+
doc <- fmap (reader startParserState . convertTabs . intercalate "\n") (readSources sources)
let doc' = foldr ($) doc transforms
doc'' <- do
#ifdef _CITEPROC
- processBiblio cslFile refs doc'
+ processBiblio csl refs doc'
#else
return doc'
#endif