@@ -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
@@ -937,7 +947,7 @@ defaultWriterName x =
937 ".fb2" -> "fb2"
947 ".fb2" -> "fb2"
938 ".opml" -> "opml"
948 ".opml" -> "opml"
939 ['.',y] | y `elem` ['1'..'9'] -> "man"
949 ['.',y] | y `elem` ['1'..'9'] -> "man"
940− _ -> "html"
950+ _ -> "html"
942-- Transformations of a Pandoc document post-parsing:
952-- Transformations of a Pandoc document post-parsing:
@@ -967,7 +977,7 @@ applyFilters filters args d =
967main :: IO ()
977main :: IO ()
970− rawArgs <- liftM (map UTF8.decodeArg) getArgs
980+ rawArgs <- map UTF8.decodeArg <$> getArgs
971 prg <- getProgName
981 prg <- getProgName
972 let compatMode = (prg == "hsmarkdown")
982 let compatMode = (prg == "hsmarkdown")
@@ -1002,7 +1012,7 @@ main = do
1002 , optTemplate = templatePath
1012 , optTemplate = templatePath
1003 , optOutputFile = outputFile
1013 , optOutputFile = outputFile
1004 , optNumberSections = numberSections
1014 , optNumberSections = numberSections
1005− , optNumberOffset = numberFrom
1015+ , optNumberOffset = numberFrom
1006 , optSectionDivs = sectionDivs
1016 , optSectionDivs = sectionDivs
1007 , optIncremental = incremental
1017 , optIncremental = incremental
1008 , optSelfContained = selfContained
1018 , optSelfContained = selfContained
@@ -1050,18 +1060,17 @@ main = do
1050 exitWith ExitSuccess
1060 exitWith ExitSuccess
1052 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1062 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1053− let filters' = case M.lookup "bibliography" metadata of
1063+ let needsCiteproc = isJust (M.lookup "bibliography" metadata) &&
1054− Just _ | optCiteMethod opts /= Natbib &&
1064+ optCiteMethod opts `notElem` [Natbib, Biblatex] &&
1055− optCiteMethod opts /= Biblatex &&
1065+ "pandoc-citeproc" `notElem` map takeBaseName filters
1056− all (\f -> takeBaseName f /= "pandoc-citeproc")
1057− filters -> "pandoc-citeproc" : filters
1066+ let filters' = if needsCiteproc then "pandoc-citeproc" : filters
1058− _ -> filters
1067+ else filters
1060 let sources = if ignoreArgs then [] else args
1069 let sources = if ignoreArgs then [] else args
1062 datadir <- case mbDataDir of
1071 datadir <- case mbDataDir of
1063 Nothing -> E.catch
1072 Nothing -> E.catch
1064− (liftM Just $ getAppUserDataDirectory "pandoc")
1073+ (Just <$> getAppUserDataDirectory "pandoc")
1065 (\e -> let _ = (e :: E.SomeException)
1074 (\e -> let _ = (e :: E.SomeException)
1066 in return Nothing)
1075 in return Nothing)
1067 Just _ -> return mbDataDir
1076 Just _ -> return mbDataDir
@@ -1092,7 +1101,8 @@ main = do
1092 else case getWriter writerName' of
1101 else case getWriter writerName' of
1093 Left e -> err 9 $
1102 Left e -> err 9 $
1094 if writerName' == "pdf"
1103 if writerName' == "pdf"
1095− then e ++ "\nTo create a pdf with pandoc, use " ++
1105+ "\nTo create a pdf with pandoc, use " ++
1096 "the latex or beamer writer and specify\n" ++
1106 "the latex or beamer writer and specify\n" ++
1097 "an output file with .pdf extension " ++
1107 "an output file with .pdf extension " ++
1098 "(pandoc -t latex -o filename.pdf)."
1108 "(pandoc -t latex -o filename.pdf)."
@@ -1144,20 +1154,22 @@ main = do
1145 dztempl <- readDataFileUTF8 datadir
1155 dztempl <- readDataFileUTF8 datadir
1146 ("dzslides" </> "template.html")
1156 ("dzslides" </> "template.html")
1157+ let dzline = "<!-- {{{{ dzslides core"
1158+ let dzcore = unlines
1147− let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
1159+ $ dropWhile (not . (dzline `isPrefixOf`))
1148− $ lines dztempl
1160+ $ lines dztempl
1149 return $ ("dzslides-core", dzcore) : variables'
1161 return $ ("dzslides-core", dzcore) : variables'
1150 else return variables'
1162 else return variables'
1152 let sourceURL = case sources of
1164 let sourceURL = case sources of
1153− [] -> Nothing
1165+ [] -> Nothing
1154− (x:_) -> case parseURI x of
1166+ (x:_) -> case parseURI x of
1156− | uriScheme u `elem` ["http:","https:"] ->
1168+ | uriScheme u `elem` ["http:","https:"] ->
1157− Just $ show u{ uriPath = "",
1169+ Just $ show u{ uriPath = "",
1158− uriQuery = "",
1170+ uriQuery = "",
1159− uriFragment = "" }
1171+ uriFragment = "" }
1160− _ -> Nothing
1172+ _ -> Nothing
1162 let readerOpts = def{ readerSmart = smart || (texLigatures &&
1174 let readerOpts = def{ readerSmart = smart || (texLigatures &&
1163 (laTeXOutput || "context" `isPrefixOf` writerName'))
1175 (laTeXOutput || "context" `isPrefixOf` writerName'))
@@ -1193,11 +1205,14 @@ main = do
1193 let readFiles [] = error "Cannot read archive from stdin"
1205 let readFiles [] = error "Cannot read archive from stdin"
1194 readFiles (x:_) = B.readFile x
1206 readFiles (x:_) = B.readFile x
1196− let convertTabs = tabFilter (if (preserveTabs || readerName' == "t2t") then 0 else tabStop)
1208+ let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1198− let handleIncludes' = if readerName' == "latex" || readerName' == "latex+lhs"
1212+ let handleIncludes' = if readerName' == "latex" ||
1213+ readerName' == "latex+lhs"
1199− then handleIncludes
1214+ then handleIncludes
1200− else return
1215+ else return
1202 (doc, media) <-
1217 (doc, media) <-
1203 case reader of
1218 case reader of