@@ -57,7 +57,8 @@ import System.IO.Error ( isDoesNotExistError )
5757import qualified Control.Exception as E
5858import Control.Exception.Extensible ( throwIO )
5959import qualified Text.Pandoc.UTF8 as UTF8
60−import Control.Monad (when, unless, liftM, (>=>))
60+import Control.Monad (when, unless, (>=>))
61+import Data.Maybe (isJust)
6162import Data.Foldable (foldrM)
6263import Network.URI (parseURI, isURI, URI(..))
6364import qualified Data.ByteString.Lazy as B
@@ -74,10 +75,13 @@ import Data.Monoid
7475type Transform = Pandoc -> Pandoc
7576
7677copyrightMessage :: String
77−copyrightMessage = "\nCopyright (C) 2006-2014 John MacFarlane\n" ++
78− "Web: http://johnmacfarlane.net/pandoc\n" ++
79− "This is free software; see the source for copying conditions. There is no\n" ++
80− "warranty, not even for merchantability or fitness for a particular purpose."
78+copyrightMessage = unlines [
79+ "",
80+ "Copyright (C) 2006-2014 John MacFarlane",
81+ "Web: http://johnmacfarlane.net/pandoc",
82+ "This is free software; see the source for copying conditions.",
83+ "There is no warranty, not even for merchantability or fitness",
84+ "for a particular purpose." ]
8185
8286compileInfo :: String
8387compileInfo =
@@ -91,15 +95,21 @@ compileInfo =
9195-- comma separated words in lines with a maximum line length.
9296wrapWords :: Int -> Int -> [String] -> String
9397wrapWords indent c = wrap' (c - indent) (c - indent)
94− where wrap' _ _ [] = ""
95− wrap' cols remaining (x:xs) = if remaining == cols
96− then x ++ wrap' cols (remaining - length x) xs
97− else if (length x + 1) > remaining
98− then ",\n" ++ replicate indent ' ' ++ x ++ wrap' cols (cols - length x) xs
99− else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
98+ where
99+ wrap' _ _ [] = ""
100+ wrap' cols remaining (x:xs)
101+ | remaining == cols =
102+ x ++ wrap' cols (remaining - length x) xs
103+ | (length x + 1) > remaining =
104+ ",\n" ++ replicate indent ' ' ++ x ++
105+ wrap' cols (cols - length x) xs
106+ | otherwise =
107+ ", " ++ x ++
108+ wrap' cols (remaining - length x - 2) xs
100109
101110isTextFormat :: 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"]
103113
104114externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
105115externalFilter f args' d = do
@@ -938,7 +948,7 @@ defaultWriterName x =
938948 ".fb2" -> "fb2"
939949 ".opml" -> "opml"
940950 ['.',y] | y `elem` ['1'..'9'] -> "man"
941− _ -> "html"
951+ _ -> "html"
942952
943953-- Transformations of a Pandoc document post-parsing:
944954
@@ -968,7 +978,7 @@ applyFilters filters args d =
968978main :: IO ()
969979main = do
970980
971− rawArgs <- liftM (map UTF8.decodeArg) getArgs
981+ rawArgs <- map UTF8.decodeArg <$> getArgs
972982 prg <- getProgName
973983 let compatMode = (prg == "hsmarkdown")
974984
@@ -1003,7 +1013,7 @@ main = do
10031013 , optTemplate = templatePath
10041014 , optOutputFile = outputFile
10051015 , optNumberSections = numberSections
1006− , optNumberOffset = numberFrom
1016+ , optNumberOffset = numberFrom
10071017 , optSectionDivs = sectionDivs
10081018 , optIncremental = incremental
10091019 , optSelfContained = selfContained
@@ -1051,18 +1061,17 @@ main = do
10511061 exitWith ExitSuccess
10521062
10531063 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1054− let filters' = case M.lookup "bibliography" metadata of
1055− Just _ | optCiteMethod opts /= Natbib &&
1056− optCiteMethod opts /= Biblatex &&
1057− all (\f -> takeBaseName f /= "pandoc-citeproc")
1058− filters -> "pandoc-citeproc" : filters
1059− _ -> filters
1064+ let needsCiteproc = isJust (M.lookup "bibliography" metadata) &&
1065+ optCiteMethod opts `notElem` [Natbib, Biblatex] &&
1066+ "pandoc-citeproc" `notElem` map takeBaseName filters
1067+ let filters' = if needsCiteproc then "pandoc-citeproc" : filters
1068+ else filters
10601069
10611070 let sources = if ignoreArgs then [] else args
10621071
10631072 datadir <- case mbDataDir of
10641073 Nothing -> E.catch
1065− (liftM Just $ getAppUserDataDirectory "pandoc")
1074+ (Just <$> getAppUserDataDirectory "pandoc")
10661075 (\e -> let _ = (e :: E.SomeException)
10671076 in return Nothing)
10681077 Just _ -> return mbDataDir
@@ -1093,7 +1102,8 @@ main = do
10931102 else case getWriter writerName' of
10941103 Left e -> err 9 $
10951104 if writerName' == "pdf"
1096− then e ++ "\nTo create a pdf with pandoc, use " ++
1105+ then e ++
1106+ "\nTo create a pdf with pandoc, use " ++
10971107 "the latex or beamer writer and specify\n" ++
10981108 "an output file with .pdf extension " ++
10991109 "(pandoc -t latex -o filename.pdf)."
@@ -1145,20 +1155,22 @@ main = do
11451155 then do
11461156 dztempl <- readDataFileUTF8 datadir
11471157 ("dzslides" </> "template.html")
1148− let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
1149− $ lines dztempl
1158+ let dzline = "<!-- {{{{ dzslides core"
1159+ let dzcore = unlines
1160+ $ dropWhile (not . (dzline `isPrefixOf`))
1161+ $ lines dztempl
11501162 return $ ("dzslides-core", dzcore) : variables'
11511163 else return variables'
11521164
11531165 let sourceURL = case sources of
1154− [] -> Nothing
1155− (x:_) -> case parseURI x of
1156− Just u
1157− | uriScheme u `elem` ["http:","https:"] ->
1158− Just $ show u{ uriPath = "",
1159− uriQuery = "",
1160− uriFragment = "" }
1161− _ -> Nothing
1166+ [] -> Nothing
1167+ (x:_) -> case parseURI x of
1168+ Just u
1169+ | uriScheme u `elem` ["http:","https:"] ->
1170+ Just $ show u{ uriPath = "",
1171+ uriQuery = "",
1172+ uriFragment = "" }
1173+ _ -> Nothing
11621174
11631175 let readerOpts = def{ readerSmart = smart || (texLigatures &&
11641176 (laTeXOutput || "context" `isPrefixOf` writerName'))
@@ -1194,11 +1206,14 @@ main = do
11941206 let readFiles [] = error "Cannot read archive from stdin"
11951207 readFiles (x:_) = B.readFile x
11961208
1197− let convertTabs = tabFilter (if (preserveTabs || readerName' == "t2t") then 0 else tabStop)
1209+ let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1210+ then 0
1211+ else tabStop)
11981212
1199− let handleIncludes' = if readerName' == "latex" || readerName' == "latex+lhs"
1200− then handleIncludes
1201− else return
1213+ let handleIncludes' = if readerName' == "latex" ||
1214+ readerName' == "latex+lhs"
1215+ then handleIncludes
1216+ else return
12021217
12031218 (doc, media) <-
12041219 case reader of