@@ -47,6 +47,10 @@ import System.IO ( stdout, stderr )
4747#else
4848import System.IO
4949#endif
50+#ifdef _CITEPROC
51+import Text.CSL
52+import Text.Pandoc.Biblio
53+#endif
5054
5155copyrightMessage :: String
5256copyrightMessage = "\nCopyright (C) 2006-7 John MacFarlane\n" ++
@@ -55,15 +59,25 @@ copyrightMessage = "\nCopyright (C) 2006-7 John MacFarlane\n" ++
5559 "warranty, not even for merchantability or fitness for a particular purpose."
5660
5761compileInfo :: String
58−compileInfo = "Compiled" ++
62+compileInfo =
5963#ifdef _UTF8
60− " with UTF-8 support" ++
64+ " +utf8" ++
65+#else
66+ " -utf8" ++
67+#endif
68+#ifdef _CITEPROC
69+ " +citeproc" ++
70+#else
71+ " -citeproc" ++
72+#endif
73+#ifdef _HIGHLIGHTING
74+ " +highlighting" ++
6175#else
62− " without UTF-8 support" ++
76+ " -highlighting" ++
6377#endif
6478 if null languages
65− then " and without syntax highlighting support."
66− else " and with syntax highlighting support for:\n" ++
79+ then "\n"
80+ else "\nCompiled with syntax highlighting support for:\n" ++
6781 (unlines $ map unwords $ chunk 5 $ map (\s -> s ++ replicate (15 - length s) ' ') languages)
6882
6983-- | Splits a list into groups of at most n.
@@ -137,6 +151,10 @@ data Opt = Opt
137151 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
138152 , optWrapText :: Bool -- ^ Wrap text
139153 , optSanitizeHTML :: Bool -- ^ Sanitize HTML
154+#ifdef _CITEPROC
155+ , optModsFile :: String
156+ , optCslFile :: String
157+#endif
140158 }
141159
142160-- | Defaults for command-line options.
@@ -166,6 +184,10 @@ defaultOpts = Opt
166184 , optReferenceLinks = False
167185 , optWrapText = True
168186 , optSanitizeHTML = False
187+#ifdef _CITEPROC
188+ , optModsFile = []
189+ , optCslFile = []
190+#endif
169191 }
170192
171193-- | A list of functions, each transforming the options data structure
@@ -333,13 +355,24 @@ options =
333355 exitWith ExitSuccess)
334356 "FORMAT")
335357 "" -- "Print default header for FORMAT"
336−
358+#ifdef _CITEPROC
359+ , Option "" ["mods"]
360+ (ReqArg
361+ (\arg opt -> return opt { optModsFile = arg} )
362+ "FILENAME")
363+ ""
364+ , Option "" ["csl"]
365+ (ReqArg
366+ (\arg opt -> return opt { optCslFile = arg} )
367+ "FILENAME")
368+ ""
369+#endif
337370 , Option "" ["dump-args"]
338371 (NoArg
339372 (\opt -> return opt { optDumpArgs = True }))
340373 "" -- "Print output filename and arguments to stdout."
341374
342− , Option "" ["ignore-args"]
375+ , Option "" ["ignore-args"]
343376 (NoArg
344377 (\opt -> return opt { optIgnoreArgs = True }))
345378 "" -- "Ignore command-line arguments."
@@ -348,7 +381,7 @@ options =
348381 (NoArg
349382 (\_ -> do
350383 prg <- getProgName
351− hPutStrLn stderr (prg ++ " " ++ pandocVersion ++ "\n" ++ compileInfo ++
384+ hPutStrLn stderr (prg ++ " " ++ pandocVersion ++ compileInfo ++
352385 copyrightMessage)
353386 exitWith $ ExitFailure 4))
354387 "" -- "Print version"
@@ -464,6 +497,10 @@ main = do
464497 , optReferenceLinks = referenceLinks
465498 , optWrapText = wrap
466499 , optSanitizeHTML = sanitize
500+#ifdef _CITEPROC
501+ , optModsFile = modsFile
502+ , optCslFile = cslFile
503+#endif
467504 } = opts
468505
469506 if dumpArgs
@@ -513,11 +550,18 @@ main = do
513550
514551 let standalone' = (standalone && not strict) || writerName' == "odt"
515552
553+#ifdef _CITEPROC
554+ refs <- if null modsFile then return [] else readModsColletionFile modsFile
555+#endif
556+
516557 let startParserState =
517558 defaultParserState { stateParseRaw = parseRaw,
518559 stateTabStop = tabStop,
519560 stateSanitizeHTML = sanitize,
520561 stateStandalone = standalone',
562+#ifdef _CITEPROC
563+ stateCitations = map citeKey refs,
564+#endif
521565 stateSmart = smart || writerName' `elem`
522566 ["latex", "context"],
523567 stateColumns = columns,
@@ -564,11 +608,12 @@ main = do
564608 then putStrLn
565609 else writeFile outputFile . (++ "\n")
566610
567− (readSources sources) >>= writeOutput .
568− writer writerOptions .
569− reader startParserState .
570− tabFilter tabStop .
571− joinWithSep "\n"
611+ fmap (reader startParserState . tabFilter tabStop . joinWithSep "\n")
612+ (readSources sources) >>=
613+#ifdef _CITEPROC
614+ processBiblio cslFile refs >>=
615+#endif
616+ writeOutput . writer writerOptions
572617
573618 where
574619 readSources [] = mapM readSource ["-"]