@@ -35,7 +35,7 @@ import Text.Pandoc.PDF (makePDF)
35import Text.Pandoc.Readers.LaTeX (handleIncludes)
35import Text.Pandoc.Readers.LaTeX (handleIncludes)
36import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8, readDataFile,
36import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8, readDataFile,
37 safeRead, headerShift, normalize, err, warn )
37 safeRead, headerShift, normalize, err, warn )
38−import Text.Pandoc.XML ( toEntities, fromEntities )
38+import Text.Pandoc.XML ( toEntities )
39import Text.Pandoc.SelfContained ( makeSelfContained )
39import Text.Pandoc.SelfContained ( makeSelfContained )
40import Text.Pandoc.Process (pipeProcess)
40import Text.Pandoc.Process (pipeProcess)
41import Text.Highlighting.Kate ( languages, Style, tango, pygments,
41import Text.Highlighting.Kate ( languages, Style, tango, pygments,
@@ -46,20 +46,18 @@ import System.FilePath
46import System.Console.GetOpt
46import System.Console.GetOpt
47import Data.Char ( toLower )
47import Data.Char ( toLower )
48import Data.List ( intercalate, isPrefixOf, sort )
48import Data.List ( intercalate, isPrefixOf, sort )
49−import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
49+import System.Directory ( getAppUserDataDirectory, findExecutable )
50import System.IO ( stdout, stderr )
50import System.IO ( stdout, stderr )
51import System.IO.Error ( isDoesNotExistError )
51import System.IO.Error ( isDoesNotExistError )
52import qualified Control.Exception as E
52import qualified Control.Exception as E
53import Control.Exception.Extensible ( throwIO )
53import Control.Exception.Extensible ( throwIO )
54import qualified Text.Pandoc.UTF8 as UTF8
54import qualified Text.Pandoc.UTF8 as UTF8
55−import qualified Text.CSL as CSL
56import Control.Monad (when, unless, liftM)
55import Control.Monad (when, unless, liftM)
57import Data.Foldable (foldrM)
56import Data.Foldable (foldrM)
58import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
57import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
59import Network.URI (parseURI, isURI, URI(..))
58import Network.URI (parseURI, isURI, URI(..))
60import qualified Data.ByteString.Lazy as B
59import qualified Data.ByteString.Lazy as B
61import qualified Data.ByteString as BS
60import qualified Data.ByteString as BS
62−import Text.CSL.Reference (Reference(..))
63import Data.Aeson (eitherDecode', encode)
61import Data.Aeson (eitherDecode', encode)
65copyrightMessage :: String
63copyrightMessage :: String
@@ -70,7 +68,7 @@ copyrightMessage = "\nCopyright (C) 2006-2013 John MacFarlane\n" ++
71compileInfo :: String
69compileInfo :: String
72compileInfo =
70compileInfo =
73− "\nCompiled with citeproc-hs " ++ VERSION_citeproc_hs ++ ", texmath " ++
71+ "\nCompiled with texmath " ++
74 VERSION_texmath ++ ", highlighting-kate " ++ VERSION_highlighting_kate ++
72 VERSION_texmath ++ ", highlighting-kate " ++ VERSION_highlighting_kate ++
75 ".\nSyntax highlighting is supported for the following languages:\n " ++
73 ".\nSyntax highlighting is supported for the following languages:\n " ++
76 wrapWords 4 78
74 wrapWords 4 78
@@ -91,14 +89,14 @@ isTextFormat :: String -> Bool
91isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub","epub3"]
89isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub","epub3"]
93externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
91externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
94−externalFilter f args' d = E.handle filterException $
92+externalFilter f args' d = do
93+ (exitcode, outbs, errbs) <- E.handle filterException $
95− do (exitcode, outbs, errbs) <- pipeProcess Nothing f args' $ encode d
94+ pipeProcess Nothing f args' $ encode d
96 when (not $ B.null errbs) $ B.hPutStr stderr errbs
95 when (not $ B.null errbs) $ B.hPutStr stderr errbs
97 case exitcode of
96 case exitcode of
98 ExitSuccess -> return $ either error id $ eitherDecode' outbs
97 ExitSuccess -> return $ either error id $ eitherDecode' outbs
99− ExitFailure _ -> err 83 $ "Error running filter " ++ f ++ "\n" ++
98+ ExitFailure _ -> err 83 $ "Error running filter " ++ f
100− UTF8.toStringLazy outbs
101− where filterException :: E.SomeException -> IO Pandoc
99+ where filterException :: E.SomeException -> IO a
102 filterException e = err 83 $ "Error running filter " ++ f ++
100 filterException e = err 83 $ "Error running filter " ++ f ++
103 "\n" ++ show e
101 "\n" ++ show e
@@ -146,9 +144,6 @@ data Opt = Opt
146 , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
144 , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
147 , optDataDir :: Maybe FilePath
145 , optDataDir :: Maybe FilePath
148 , optCiteMethod :: CiteMethod -- ^ Method to output cites
146 , optCiteMethod :: CiteMethod -- ^ Method to output cites
149− , optBibliography :: [String]
150− , optCslFile :: Maybe FilePath
151− , optAbbrevsFile :: Maybe FilePath
152 , optListings :: Bool -- ^ Use listings package for code blocks
147 , optListings :: Bool -- ^ Use listings package for code blocks
153 , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
148 , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
154 , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
149 , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
@@ -203,9 +198,6 @@ defaultOpts = Opt
203 , optIndentedCodeClasses = []
198 , optIndentedCodeClasses = []
204 , optDataDir = Nothing
199 , optDataDir = Nothing
205 , optCiteMethod = Citeproc
200 , optCiteMethod = Citeproc
206− , optBibliography = []
207− , optCslFile = Nothing
208− , optAbbrevsFile = Nothing
209 , optListings = False
201 , optListings = False
210 , optLaTeXEngine = "pdflatex"
202 , optLaTeXEngine = "pdflatex"
211 , optSlideLevel = Nothing
203 , optSlideLevel = Nothing
@@ -288,7 +280,7 @@ options =
288 "STRING")
280 "STRING")
289 "" -- "Classes (whitespace- or comma-separated) to use for indented code-blocks"
281 "" -- "Classes (whitespace- or comma-separated) to use for indented code-blocks"
291− , Option "" ["filter"]
283+ , Option "F" ["filter"]
293 (\arg opt -> return opt { optPlugins = externalFilter arg :
285 (\arg opt -> return opt { optPlugins = externalFilter arg :
294 optPlugins opt })
286 optPlugins opt })
@@ -650,24 +642,6 @@ options =
650 "PROGRAM")
642 "PROGRAM")
651 "" -- "Name of latex program to use in generating PDF"
643 "" -- "Name of latex program to use in generating PDF"
653− , Option "" ["bibliography"]
655− (\arg opt -> return opt { optBibliography = (optBibliography opt) ++ [arg] })
661− (\arg opt -> return opt { optCslFile = Just arg })
665− , Option "" ["citation-abbreviations"]
667− (\arg opt -> return opt { optAbbrevsFile = Just arg })
671 , Option "" ["natbib"]
645 , Option "" ["natbib"]
673 (\opt -> return opt { optCiteMethod = Natbib }))
647 (\opt -> return opt { optCiteMethod = Natbib }))
@@ -904,9 +878,6 @@ main = do
904 , optIdentifierPrefix = idPrefix
878 , optIdentifierPrefix = idPrefix
905 , optIndentedCodeClasses = codeBlockClasses
879 , optIndentedCodeClasses = codeBlockClasses
906 , optDataDir = mbDataDir
880 , optDataDir = mbDataDir
907− , optBibliography = reffiles
908− , optCslFile = mbCsl
909− , optAbbrevsFile = cslabbrevs
910 , optCiteMethod = citeMethod
881 , optCiteMethod = citeMethod
911 , optListings = listings
882 , optListings = listings
912 , optLaTeXEngine = latexEngine
883 , optLaTeXEngine = latexEngine
@@ -1007,36 +978,6 @@ main = do
1007 $ lines dztempl
978 $ lines dztempl
1008 return $ ("dzslides-core", dzcore) : variables'
979 return $ ("dzslides-core", dzcore) : variables'
1009 else return variables'
980 else return variables'
1011− -- unescape reference ids, which may contain XML entities, so
1012− -- that we can do lookups with regular string equality
1013− let unescapeRefId ref = ref{ refId = fromEntities (refId ref) }
1015− refs <- mapM (\f -> E.catch (CSL.readBiblioFile f)
1016− (\e -> let _ = (e :: E.SomeException)
1017− in err 23 $ "Error reading bibliography `" ++ f ++
1018− "'" ++ "\n" ++ show e))
1020− return . map unescapeRefId . concat
1022− mbsty <- if citeMethod == Citeproc && not (null refs)
1024− csl <- CSL.parseCSL =<<
1026− Nothing -> readDataFileUTF8 datadir
1029− exists <- doesFileExist cslfile
1031− then UTF8.readFile cslfile
1033− csldir <- getAppUserDataDirectory "csl"
1034− readDataFileUTF8 (Just csldir)
1035− (replaceExtension cslfile "csl")
1036− abbrevs <- maybe (return []) CSL.readJsonAbbrevFile cslabbrevs
1037− return $ Just csl { CSL.styleAbbrevs = abbrevs }
1038− else return Nothing
1040 let sourceURL = case sources of
981 let sourceURL = case sources of
1041 [] -> Nothing
982 [] -> Nothing
1042 (x:_) -> case parseURI x of
983 (x:_) -> case parseURI x of
@@ -1054,8 +995,6 @@ main = do
1054 , readerColumns = columns
995 , readerColumns = columns
1055 , readerTabStop = tabStop
996 , readerTabStop = tabStop
1056 , readerOldDashes = oldDashes
997 , readerOldDashes = oldDashes
1057− , readerReferences = refs
1058− , readerCitationStyle = mbsty
1059 , readerIndentedCodeClasses = codeBlockClasses
998 , readerIndentedCodeClasses = codeBlockClasses
1060 , readerApplyMacros = not laTeXOutput
999 , readerApplyMacros = not laTeXOutput
1061 , readerDefaultImageExtension = defaultImageExtension
1000 , readerDefaultImageExtension = defaultImageExtension
@@ -1069,7 +1008,6 @@ main = do
1069 writerHTMLMathMethod = mathMethod,
1008 writerHTMLMathMethod = mathMethod,
1070 writerIncremental = incremental,
1009 writerIncremental = incremental,
1071 writerCiteMethod = citeMethod,
1010 writerCiteMethod = citeMethod,
1072− writerBiblioFiles = reffiles,
1073 writerIgnoreNotes = False,
1011 writerIgnoreNotes = False,
1074 writerNumberSections = numberSections,
1012 writerNumberSections = numberSections,
1075 writerNumberOffset = numberFrom,
1013 writerNumberOffset = numberFrom,