git.iko.soy/typeable/pandoc
on master help sign in
Slightly fix readability of main program file.
commit675b15458a03371ef4d72d52218319a4cf09216d authorArtyom Kazak <yom@artyom.me> dateMon 4 Aug 2014, 18:08 (12 years ago) parent141fdf9
1 file changed+52−37
pandoc.hs+52−37
pandoc.hs+52−37
@@ -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
@@ -937,7 +947,7 @@ defaultWriterName x =
937947 ".fb2" -> "fb2"
938948 ".opml" -> "opml"
939949 ['.',y] | y `elem` ['1'..'9'] -> "man"
940− _ -> "html"
950+ _ -> "html"
941951
942952-- Transformations of a Pandoc document post-parsing:
943953
@@ -967,7 +977,7 @@ applyFilters filters args d =
967977main :: IO ()
968978main = do
969979
970− rawArgs <- liftM (map UTF8.decodeArg) getArgs
980+ rawArgs <- map UTF8.decodeArg <$> getArgs
971981 prg <- getProgName
972982 let compatMode = (prg == "hsmarkdown")
973983
@@ -1002,7 +1012,7 @@ main = do
10021012 , optTemplate = templatePath
10031013 , optOutputFile = outputFile
10041014 , optNumberSections = numberSections
1005− , optNumberOffset = numberFrom
1015+ , optNumberOffset = numberFrom
10061016 , optSectionDivs = sectionDivs
10071017 , optIncremental = incremental
10081018 , optSelfContained = selfContained
@@ -1050,18 +1060,17 @@ main = do
10501060 exitWith ExitSuccess
10511061
10521062 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1053− let filters' = case M.lookup "bibliography" metadata of
1054− Just _ | optCiteMethod opts /= Natbib &&
1055− optCiteMethod opts /= Biblatex &&
1056− all (\f -> takeBaseName f /= "pandoc-citeproc")
1057− filters -> "pandoc-citeproc" : filters
1058− _ -> filters
1063+ let needsCiteproc = isJust (M.lookup "bibliography" metadata) &&
1064+ optCiteMethod opts `notElem` [Natbib, Biblatex] &&
1065+ "pandoc-citeproc" `notElem` map takeBaseName filters
1066+ let filters' = if needsCiteproc then "pandoc-citeproc" : filters
1067+ else filters
10591068
10601069 let sources = if ignoreArgs then [] else args
10611070
10621071 datadir <- case mbDataDir of
10631072 Nothing -> E.catch
1064− (liftM Just $ getAppUserDataDirectory "pandoc")
1073+ (Just <$> getAppUserDataDirectory "pandoc")
10651074 (\e -> let _ = (e :: E.SomeException)
10661075 in return Nothing)
10671076 Just _ -> return mbDataDir
@@ -1092,7 +1101,8 @@ main = do
10921101 else case getWriter writerName' of
10931102 Left e -> err 9 $
10941103 if writerName' == "pdf"
1095− then e ++ "\nTo create a pdf with pandoc, use " ++
1104+ then e ++
1105+ "\nTo create a pdf with pandoc, use " ++
10961106 "the latex or beamer writer and specify\n" ++
10971107 "an output file with .pdf extension " ++
10981108 "(pandoc -t latex -o filename.pdf)."
@@ -1144,20 +1154,22 @@ main = do
11441154 then do
11451155 dztempl <- readDataFileUTF8 datadir
11461156 ("dzslides" </> "template.html")
1147− let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
1148− $ lines dztempl
1157+ let dzline = "<!-- {{{{ dzslides core"
1158+ let dzcore = unlines
1159+ $ dropWhile (not . (dzline `isPrefixOf`))
1160+ $ lines dztempl
11491161 return $ ("dzslides-core", dzcore) : variables'
11501162 else return variables'
11511163
11521164 let sourceURL = case sources of
1153− [] -> Nothing
1154− (x:_) -> case parseURI x of
1155− Just u
1156− | uriScheme u `elem` ["http:","https:"] ->
1157− Just $ show u{ uriPath = "",
1158− uriQuery = "",
1159− uriFragment = "" }
1160− _ -> Nothing
1165+ [] -> Nothing
1166+ (x:_) -> case parseURI x of
1167+ Just u
1168+ | uriScheme u `elem` ["http:","https:"] ->
1169+ Just $ show u{ uriPath = "",
1170+ uriQuery = "",
1171+ uriFragment = "" }
1172+ _ -> Nothing
11611173
11621174 let readerOpts = def{ readerSmart = smart || (texLigatures &&
11631175 (laTeXOutput || "context" `isPrefixOf` writerName'))
@@ -1193,11 +1205,14 @@ main = do
11931205 let readFiles [] = error "Cannot read archive from stdin"
11941206 readFiles (x:_) = B.readFile x
11951207
1196− let convertTabs = tabFilter (if (preserveTabs || readerName' == "t2t") then 0 else tabStop)
1208+ let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1209+ then 0
1210+ else tabStop)
11971211
1198− let handleIncludes' = if readerName' == "latex" || readerName' == "latex+lhs"
1199− then handleIncludes
1200− else return
1212+ let handleIncludes' = if readerName' == "latex" ||
1213+ readerName' == "latex+lhs"
1214+ then handleIncludes
1215+ else return
12011216
12021217 (doc, media) <-
12031218 case reader of