@@ -57,7 +57,8 @@ import System.IO.Error ( isDoesNotExistError )
57import qualified Control.Exception as E
57import qualified Control.Exception as E
58import Control.Exception.Extensible ( throwIO )
58import Control.Exception.Extensible ( throwIO )
59import qualified Text.Pandoc.UTF8 as UTF8
59import qualified Text.Pandoc.UTF8 as UTF8
60−import Control.Monad (when, unless, liftM, (>=>))
60+import Control.Monad (when, unless, (>=>))
61+import Data.Maybe (isJust)
61import Data.Foldable (foldrM)
62import Data.Foldable (foldrM)
62import Network.URI (parseURI, isURI, URI(..))
63import Network.URI (parseURI, isURI, URI(..))
63import qualified Data.ByteString.Lazy as B
64import qualified Data.ByteString.Lazy as B
@@ -74,10 +75,13 @@ import Data.Monoid
74type Transform = Pandoc -> Pandoc
75type Transform = Pandoc -> Pandoc
76copyrightMessage :: String
77copyrightMessage :: String
78+copyrightMessage = unlines [
77−copyrightMessage = "\nCopyright (C) 2006-2014 John MacFarlane\n" ++
80+ "Copyright (C) 2006-2014 John MacFarlane",
78− "Web: http://johnmacfarlane.net/pandoc\n" ++
81+ "Web: http://johnmacfarlane.net/pandoc",
79− "This is free software; see the source for copying conditions. There is no\n" ++
82+ "This is free software; see the source for copying conditions.",
80− "warranty, not even for merchantability or fitness for a particular purpose."
83+ "There is no warranty, not even for merchantability or fitness",
84+ "for a particular purpose." ]
82compileInfo :: String
86compileInfo :: String
83compileInfo =
87compileInfo =
@@ -91,15 +95,21 @@ compileInfo =
91-- comma separated words in lines with a maximum line length.
95-- comma separated words in lines with a maximum line length.
92wrapWords :: Int -> Int -> [String] -> String
96wrapWords :: Int -> Int -> [String] -> String
93wrapWords indent c = wrap' (c - indent) (c - indent)
97wrapWords indent c = wrap' (c - indent) (c - indent)
94− where wrap' _ _ [] = ""
99+ wrap' _ _ [] = ""
95− wrap' cols remaining (x:xs) = if remaining == cols
100+ wrap' cols remaining (x:xs)
101+ | remaining == cols =
96− then x ++ wrap' cols (remaining - length x) xs
102+ x ++ wrap' cols (remaining - length x) xs
97− else if (length x + 1) > remaining
103+ | (length x + 1) > remaining =
104+ ",\n" ++ replicate indent ' ' ++ x ++
98− then ",\n" ++ replicate indent ' ' ++ x ++ wrap' cols (cols - length x) xs
105+ wrap' cols (cols - length x) xs
99− else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
108+ wrap' cols (remaining - length x - 2) xs
101isTextFormat :: String -> Bool
110isTextFormat :: String -> Bool
102−isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub","epub3"]
111+isTextFormat s = takeWhile (`notElem` "+-") s `notElem` binaries
112+ where binaries = ["odt","docx","epub","epub3"]
104externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
114externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
105externalFilter f args' d = do
115externalFilter f args' d = do
@@ -938,7 +948,7 @@ defaultWriterName x =
938 ".fb2" -> "fb2"
948 ".fb2" -> "fb2"
939 ".opml" -> "opml"
949 ".opml" -> "opml"
940 ['.',y] | y `elem` ['1'..'9'] -> "man"
950 ['.',y] | y `elem` ['1'..'9'] -> "man"
941− _ -> "html"
951+ _ -> "html"
943-- Transformations of a Pandoc document post-parsing:
953-- Transformations of a Pandoc document post-parsing:
@@ -968,7 +978,7 @@ applyFilters filters args d =
968main :: IO ()
978main :: IO ()
971− rawArgs <- liftM (map UTF8.decodeArg) getArgs
981+ rawArgs <- map UTF8.decodeArg <$> getArgs
972 prg <- getProgName
982 prg <- getProgName
973 let compatMode = (prg == "hsmarkdown")
983 let compatMode = (prg == "hsmarkdown")
@@ -1003,7 +1013,7 @@ main = do
1003 , optTemplate = templatePath
1013 , optTemplate = templatePath
1004 , optOutputFile = outputFile
1014 , optOutputFile = outputFile
1005 , optNumberSections = numberSections
1015 , optNumberSections = numberSections
1006− , optNumberOffset = numberFrom
1016+ , optNumberOffset = numberFrom
1007 , optSectionDivs = sectionDivs
1017 , optSectionDivs = sectionDivs
1008 , optIncremental = incremental
1018 , optIncremental = incremental
1009 , optSelfContained = selfContained
1019 , optSelfContained = selfContained
@@ -1051,18 +1061,17 @@ main = do
1051 exitWith ExitSuccess
1061 exitWith ExitSuccess
1053 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1063 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1054− let filters' = case M.lookup "bibliography" metadata of
1064+ let needsCiteproc = isJust (M.lookup "bibliography" metadata) &&
1055− Just _ | optCiteMethod opts /= Natbib &&
1065+ optCiteMethod opts `notElem` [Natbib, Biblatex] &&
1056− optCiteMethod opts /= Biblatex &&
1066+ "pandoc-citeproc" `notElem` map takeBaseName filters
1057− all (\f -> takeBaseName f /= "pandoc-citeproc")
1058− filters -> "pandoc-citeproc" : filters
1067+ let filters' = if needsCiteproc then "pandoc-citeproc" : filters
1059− _ -> filters
1068+ else filters
1061 let sources = if ignoreArgs then [] else args
1070 let sources = if ignoreArgs then [] else args
1063 datadir <- case mbDataDir of
1072 datadir <- case mbDataDir of
1064 Nothing -> E.catch
1073 Nothing -> E.catch
1065− (liftM Just $ getAppUserDataDirectory "pandoc")
1074+ (Just <$> getAppUserDataDirectory "pandoc")
1066 (\e -> let _ = (e :: E.SomeException)
1075 (\e -> let _ = (e :: E.SomeException)
1067 in return Nothing)
1076 in return Nothing)
1068 Just _ -> return mbDataDir
1077 Just _ -> return mbDataDir
@@ -1093,7 +1102,8 @@ main = do
1093 else case getWriter writerName' of
1102 else case getWriter writerName' of
1094 Left e -> err 9 $
1103 Left e -> err 9 $
1095 if writerName' == "pdf"
1104 if writerName' == "pdf"
1096− then e ++ "\nTo create a pdf with pandoc, use " ++
1106+ "\nTo create a pdf with pandoc, use " ++
1097 "the latex or beamer writer and specify\n" ++
1107 "the latex or beamer writer and specify\n" ++
1098 "an output file with .pdf extension " ++
1108 "an output file with .pdf extension " ++
1099 "(pandoc -t latex -o filename.pdf)."
1109 "(pandoc -t latex -o filename.pdf)."
@@ -1145,20 +1155,22 @@ main = do
1146 dztempl <- readDataFileUTF8 datadir
1156 dztempl <- readDataFileUTF8 datadir
1147 ("dzslides" </> "template.html")
1157 ("dzslides" </> "template.html")
1158+ let dzline = "<!-- {{{{ dzslides core"
1159+ let dzcore = unlines
1148− let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
1160+ $ dropWhile (not . (dzline `isPrefixOf`))
1149− $ lines dztempl
1161+ $ lines dztempl
1150 return $ ("dzslides-core", dzcore) : variables'
1162 return $ ("dzslides-core", dzcore) : variables'
1151 else return variables'
1163 else return variables'
1153 let sourceURL = case sources of
1165 let sourceURL = case sources of
1154− [] -> Nothing
1166+ [] -> Nothing
1155− (x:_) -> case parseURI x of
1167+ (x:_) -> case parseURI x of
1157− | uriScheme u `elem` ["http:","https:"] ->
1169+ | uriScheme u `elem` ["http:","https:"] ->
1158− Just $ show u{ uriPath = "",
1170+ Just $ show u{ uriPath = "",
1159− uriQuery = "",
1171+ uriQuery = "",
1160− uriFragment = "" }
1172+ uriFragment = "" }
1161− _ -> Nothing
1173+ _ -> Nothing
1163 let readerOpts = def{ readerSmart = smart || (texLigatures &&
1175 let readerOpts = def{ readerSmart = smart || (texLigatures &&
1164 (laTeXOutput || "context" `isPrefixOf` writerName'))
1176 (laTeXOutput || "context" `isPrefixOf` writerName'))
@@ -1194,11 +1206,14 @@ main = do
1194 let readFiles [] = error "Cannot read archive from stdin"
1206 let readFiles [] = error "Cannot read archive from stdin"
1195 readFiles (x:_) = B.readFile x
1207 readFiles (x:_) = B.readFile x
1197− let convertTabs = tabFilter (if (preserveTabs || readerName' == "t2t") then 0 else tabStop)
1209+ let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1199− let handleIncludes' = if readerName' == "latex" || readerName' == "latex+lhs"
1213+ let handleIncludes' = if readerName' == "latex" ||
1214+ readerName' == "latex+lhs"
1200− then handleIncludes
1215+ then handleIncludes
1201− else return
1216+ else return
1203 (doc, media) <-
1218 (doc, media) <-
1204 case reader of
1219 case reader of