git.iko.soy/typeable/pandoc
on master help sign in
hlint suggestions.
commitb61a51ee1551c62558369d9bcdaff32de7f3e2eb authorJohn MacFarlane <jgm@berkeley.edu> dateFri 2 Jun 2017, 15:06 (9 years ago) parent18f86a0
8 files changed+37−36
pandoc.hs+1 src/Text/Pandoc/App.hs+1 src/Text/Pandoc/CSS.hs+1−1 src/Text/Pandoc/Class.hs+1−1 src/Text/Pandoc/Compat/Time.hs+1−1 src/Text/Pandoc/Error.hs+1−1 src/Text/Pandoc/Highlighting.hs+3−3 src/Text/Pandoc/ImageSize.hs+28−29
pandoc.hs+1
@@ -40,3 +40,4 @@ import Text.Pandoc.Error (PandocError, handleError)
4040main :: IO ()
4141main = E.catch (parseOptions options defaultOpts >>= convertWithOpts)
4242 (\(e :: PandocError) -> handleError (Left e))
43+
src/Text/Pandoc/App.hs+1
@@ -1554,3 +1554,4 @@ splitField s =
15541554 case break (`elem` ":=") s of
15551555 (k,_:v) -> (k,v)
15561556 (k,[]) -> (k,"true")
1557+
src/Text/Pandoc/CSS.hs+1−1
@@ -11,7 +11,7 @@ import Text.Parsec.String
1111ruleParser :: Parser (String, String)
1212ruleParser = do
1313 p <- many1 (noneOf ":") <* char ':'
14− v <- many1 (noneOf ":;") <* (optional $ char ';') <* spaces
14+ v <- many1 (noneOf ":;") <* optional (char ';') <* spaces
1515 return (trim p, trim v)
1616
1717styleAttrParser :: Parser [(String, String)]
src/Text/Pandoc/Class.hs+1−1
@@ -365,7 +365,7 @@ fillMediaBag sourceURL d = walkM handleImage d
365365 let fname = basename <.> ext
366366 insertMedia fname mt bs'
367367 return $ Image attr lab (fname, tit))
368− (\e ->
368+ (\e ->
369369 case e of
370370 PandocResourceNotFound _ -> do
371371 report $ CouldNotFetchResource src
src/Text/Pandoc/Compat/Time.hs+1−1
@@ -27,4 +27,4 @@ where
2727import Data.Time
2828import System.Locale ( defaultTimeLocale )
2929
30−#endif
30+#endif
src/Text/Pandoc/Error.hs+1−1
@@ -83,7 +83,7 @@ handleError (Left e) =
8383 errColumn = sourceColumn errPos
8484 ls = lines input ++ [""]
8585 errorInFile = if length ls > errLine - 1
86− then concat ["\n", (ls !! (errLine - 1))
86+ then concat ["\n", ls !! (errLine - 1)
8787 ,"\n", replicate (errColumn - 1) ' '
8888 ,"^"]
8989 else ""
src/Text/Pandoc/Highlighting.hs+3−3
@@ -91,7 +91,7 @@ highlight syntaxmap formatter (_, classes, keyvals) rawCode =
9191 , traceOutput = False }
9292 classes' = map T.pack classes
9393 rawCode' = T.pack rawCode
94− in case msum (map (\l -> lookupSyntax l syntaxmap) classes') of
94+ in case msum (map ((`lookupSyntax` syntaxmap)) classes') of
9595 Nothing
9696 | numberLines fmtOpts -> Right
9797 $ formatter fmtOpts{ codeClasses = [],
@@ -100,9 +100,9 @@ highlight syntaxmap formatter (_, classes, keyvals) rawCode =
100100 $ T.lines rawCode'
101101 | otherwise -> Left ""
102102 Just syntax ->
103− (formatter fmtOpts{ codeClasses =
103+ formatter fmtOpts{ codeClasses =
104104 [T.toLower (sShortname syntax)],
105− containerClasses = classes' }) <$>
105+ containerClasses = classes' } <$>
106106 tokenize tokenizeOpts syntax rawCode'
107107
108108-- Functions for correlating latex listings package's language names
src/Text/Pandoc/ImageSize.hs+28−29
@@ -120,7 +120,7 @@ imageType img = case B.take 4 img of
120120 | findSvgTag img
121121 -> return Svg
122122 "%!PS"
123− | (B.take 4 $ B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
123+ | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
124124 -> return Eps
125125 _ -> mzero
126126
@@ -168,7 +168,7 @@ desiredSizeInPoints opts attr s =
168168 (Nothing, Nothing) -> sizeInPoints s
169169 where
170170 ratio = fromIntegral (pxX s) / fromIntegral (pxY s)
171− getDim dir = case (dimension dir attr) of
171+ getDim dir = case dimension dir attr of
172172 Just (Percent _) -> Nothing
173173 Just dim -> Just $ inPoints opts dim
174174 Nothing -> Nothing
@@ -182,7 +182,7 @@ inEm opts dim = (64/11) * inInch opts dim
182182inInch :: WriterOptions -> Dimension -> Double
183183inInch opts dim =
184184 case dim of
185− (Pixel a) -> fromIntegral a / (fromIntegral $ writerDpi opts)
185+ (Pixel a) -> fromIntegral a / fromIntegral (writerDpi opts)
186186 (Centimeter a) -> a * 0.3937007874
187187 (Inch a) -> a
188188 (Percent _) -> 0
@@ -261,7 +261,7 @@ epsSize img = do
261261 case ls' of
262262 [] -> mzero
263263 (x:_) -> case B.words x of
264− (_:_:_:ux:uy:[]) -> do
264+ [_, _, _, ux, uy] -> do
265265 ux' <- safeRead $ B.unpack ux
266266 uy' <- safeRead $ B.unpack uy
267267 return ImageSize{
@@ -279,27 +279,26 @@ pngSize img = do
279279 let (i, rest') = B.splitAt 4 $ B.drop 4 rest
280280 guard $ i == "MHDR" || i == "IHDR"
281281 let (sizes, rest'') = B.splitAt 8 rest'
282− (x,y) <- case map fromIntegral $ unpack $ sizes of
282+ (x,y) <- case map fromIntegral $unpack sizes of
283283 ([w1,w2,w3,w4,h1,h2,h3,h4] :: [Integer]) -> return
284− ((shift w1 24) + (shift w2 16) + (shift w3 8) + w4,
285− (shift h1 24) + (shift h2 16) + (shift h3 8) + h4)
284+ (shift w1 24 + shift w2 16 + shift w3 8 + w4,
285+ shift h1 24 + shift h2 16 + shift h3 8 + h4)
286286 _ -> Nothing -- "PNG parse error"
287287 let (dpix, dpiy) = findpHYs rest''
288− return $ ImageSize { pxX = x, pxY = y, dpiX = dpix, dpiY = dpiy }
288+ return ImageSize { pxX = x, pxY = y, dpiX = dpix, dpiY = dpiy }
289289
290290findpHYs :: ByteString -> (Integer, Integer)
291−findpHYs x =
292− if B.null x || "IDAT" `B.isPrefixOf` x
293− then (72,72) -- default, no pHYs
294− else if "pHYs" `B.isPrefixOf` x
295− then let [x1,x2,x3,x4,y1,y2,y3,y4,u] = map fromIntegral
296− $ unpack $ B.take 9 $ B.drop 4 x
297− factor = if u == 1 -- dots per meter
298− then \z -> z * 254 `div` 10000
299− else const 72
300− in ( factor $ (shift x1 24) + (shift x2 16) + (shift x3 8) + x4,
301− factor $ (shift y1 24) + (shift y2 16) + (shift y3 8) + y4 )
302− else findpHYs $ B.drop 1 x -- read another byte
291+findpHYs x
292+ | B.null x || "IDAT" `B.isPrefixOf` x = (72,72)
293+ | "pHYs" `B.isPrefixOf` x =
294+ let [x1,x2,x3,x4,y1,y2,y3,y4,u] =
295+ map fromIntegral $ unpack $ B.take 9 $ B.drop 4 x
296+ factor = if u == 1 -- dots per meter
297+ then \z -> z * 254 `div` 10000
298+ else const 72
299+ in ( factor $ (shift x1 24) + (shift x2 16) + (shift x3 8) + x4,
300+ factor $ (shift y1 24) + (shift y2 16) + (shift y3 8) + y4 )
301+ | otherwise = findpHYs $ B.drop 1 x -- read another byte
303302
304303gifSize :: ByteString -> Maybe ImageSize
305304gifSize img = do
@@ -343,16 +342,16 @@ jpegSize img =
343342jfifSize :: ByteString -> Either String ImageSize
344343jfifSize rest =
345344 let [dpiDensity,dpix1,dpix2,dpiy1,dpiy2] = map fromIntegral
346− $ unpack $ B.take 5 $ B.drop 9 $ rest
345+ $ unpack $ B.take 5 $B.drop 9 rest
347346 factor = case dpiDensity of
348347 1 -> id
349− 2 -> \x -> (x * 254 `div` 10)
348+ 2 -> \x -> x * 254 `div` 10
350349 _ -> const 72
351350 dpix = factor (shift dpix1 8 + dpix2)
352351 dpiy = factor (shift dpiy1 8 + dpiy2)
353352 in case findJfifSize rest of
354353 Left msg -> Left msg
355− Right (w,h) -> Right $ ImageSize { pxX = w
354+ Right (w,h) ->Right ImageSize { pxX = w
356355 , pxY = h
357356 , dpiX = dpix
358357 , dpiY = dpiy }
@@ -386,7 +385,7 @@ runGet' p bl =
386385
387386
388387exifSize :: ByteString -> Either String ImageSize
389−exifSize bs = runGet' header $ bl
388+exifSize bs =runGet' header bl
390389 where bl = BL.fromChunks [bs]
391390 header = runExceptT $ exifHeader bl
392391-- NOTE: It would be nicer to do
@@ -456,14 +455,13 @@ exifHeader hdr = do
456455 Left msg -> throwError msg
457456 Right x -> return x
458457 return (tag, payload)
459− entries <- sequence $ replicate (fromIntegral numentries) ifdEntry
458+ entries <- replicateM (fromIntegral numentries) ifdEntry
460459 subentries <- case lookup ExifOffset entries of
461460 Just (UnsignedLong offset') -> do
462461 pos <- lift bytesRead
463462 lift $ skip (fromIntegral offset' - (fromIntegral pos - 8))
464463 numsubentries <- lift getWord16
465− sequence $
466− replicate (fromIntegral numsubentries) ifdEntry
464+ replicateM (fromIntegral numsubentries) ifdEntry
467465 _ -> return []
468466 let allentries = entries ++ subentries
469467 (wdth, hght) <- case (lookup ExifImageWidth allentries,
@@ -474,13 +472,13 @@ exifHeader hdr = do
474472 -- we return a default width and height when
475473 -- the exif header doesn't contain these
476474 let resfactor = case lookup ResolutionUnit allentries of
477− Just (UnsignedShort 1) -> (100 / 254)
475+ Just (UnsignedShort 1) -> 100 / 254
478476 _ -> 1
479477 let xres = maybe 72 (\(UnsignedRational x) -> floor $ x * resfactor)
480478 $ lookup XResolution allentries
481479 let yres = maybe 72 (\(UnsignedRational x) -> floor $ x * resfactor)
482480 $ lookup YResolution allentries
483− return $ ImageSize{
481+ return ImageSize{
484482 pxX = wdth
485483 , pxY = hght
486484 , dpiX = xres
@@ -604,3 +602,4 @@ tagTypeTable = M.fromList
604602 , (0xa300, FileSource)
605603 , (0xa301, SceneType)
606604 ]
605+