git.iko.soy/typeable/pandoc
on master help sign in
Txt2Tags reader: hlint
6e832a5Alexander Krotov
src/Text/Pandoc/Readers/Txt2Tags.hs+25−27
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ViewPatterns #-}
2{-
1{-
3Copyright (C) 2014 Matthew Pickering <matthewtpickering@gmail.com>
2Copyright (C) 2014 Matthew Pickering <matthewtpickering@gmail.com>
4
3
@@ -94,7 +93,7 @@ readTxt2Tags opts s = do
94 readWithM parseT2T (def {stateOptions = opts}) $
93 readWithM parseT2T (def {stateOptions = opts}) $
95 T.unpack (crFilter s) ++ "\n\n"
94 T.unpack (crFilter s) ++ "\n\n"
96 case parsed of
95 case parsed of
97− Right result -> return $ result
96+ Right result -> return result
98 Left e -> throwError e
97 Left e -> throwError e
99
98
100-- | Read Txt2Tags (ignoring all macros) from an input string returning
99-- | Read Txt2Tags (ignoring all macros) from an input string returning
@@ -149,7 +148,7 @@ setting = do
149 string "%!"
148 string "%!"
150 keyword <- ignoreSpacesCap (many1 alphaNum)
149 keyword <- ignoreSpacesCap (many1 alphaNum)
151 char ':'
150 char ':'
152− value <- ignoreSpacesCap (manyTill anyChar (newline))
151+ value <- ignoreSpacesCap (manyTill anyChar newline)
153 return (keyword, value)
152 return (keyword, value)
154
153
155-- Blocks
154-- Blocks
@@ -158,7 +157,7 @@ parseBlocks :: T2T Blocks
158parseBlocks = mconcat <$> manyTill block eof
157parseBlocks = mconcat <$> manyTill block eof
159
158
160block :: T2T Blocks
159block :: T2T Blocks
161−block = do
160+block =
162 choice
161 choice
163 [ mempty <$ blanklines
162 [ mempty <$ blanklines
164 , quote
163 , quote
@@ -196,7 +195,7 @@ para = try $ do
196 listStart = try bulletListStart <|> orderedListStart
195 listStart = try bulletListStart <|> orderedListStart
197
196
198commentBlock :: T2T Blocks
197commentBlock :: T2T Blocks
199−commentBlock = try (blockMarkupArea (anyLine) (const mempty) "%%%") <|> comment
198+commentBlock = try (blockMarkupArea anyLine (const mempty) "%%%") <|> comment
200
199
201-- Seperator and Strong line treated the same
200-- Seperator and Strong line treated the same
202hrule :: T2T Blocks
201hrule :: T2T Blocks
@@ -230,7 +229,7 @@ orderedList = B.orderedList . compactify
230 <$> many1 (listItem orderedListStart parseBlocks)
229 <$> many1 (listItem orderedListStart parseBlocks)
231
230
232definitionList :: T2T Blocks
231definitionList :: T2T Blocks
233−definitionList = try $ do
232+definitionList = try $
234 B.definitionList . compactifyDL <$>
233 B.definitionList . compactifyDL <$>
235 many1 (listItem definitionListStart definitionListEnd)
234 many1 (listItem definitionListStart definitionListEnd)
236
235
@@ -282,17 +281,17 @@ table = try $ do
282 rows <- many1 (many commentLine *> tableRow)
281 rows <- many1 (many commentLine *> tableRow)
283 let columns = transpose rows
282 let columns = transpose rows
284 let ncolumns = length columns
283 let ncolumns = length columns
285− let aligns = map (foldr1 findAlign) (map (map fst) columns)
284+ let aligns = map (foldr1 findAlign . map fst) columns
286 let rows' = map (map snd) rows
285 let rows' = map (map snd) rows
287 let size = maximum (map length rows')
286 let size = maximum (map length rows')
288 let rowsPadded = map (pad size) rows'
287 let rowsPadded = map (pad size) rows'
289− let headerPadded = if (not (null tableHeader)) then pad size tableHeader else mempty
288+ let headerPadded = if null tableHeader then mempty else pad size tableHeader
290 return $ B.table mempty
289 return $ B.table mempty
291 (zip aligns (replicate ncolumns 0.0))
290 (zip aligns (replicate ncolumns 0.0))
292 headerPadded rowsPadded
291 headerPadded rowsPadded
293
292
294pad :: (Monoid a) => Int -> [a] -> [a]
293pad :: (Monoid a) => Int -> [a] -> [a]
295−pad n xs = xs ++ (replicate (n - length xs) mempty)
294+pad n xs = xs ++ replicate (n - length xs) mempty
296
295
297
296
298findAlign :: Alignment -> Alignment -> Alignment
297findAlign :: Alignment -> Alignment -> Alignment
@@ -315,7 +314,7 @@ genericRow start = try $ do
315tableCell :: T2T (Alignment, Blocks)
314tableCell :: T2T (Alignment, Blocks)
316tableCell = try $ do
315tableCell = try $ do
317 leftSpaces <- length <$> lookAhead (many1 space) -- Case of empty cell means we must lookAhead
316 leftSpaces <- length <$> lookAhead (many1 space) -- Case of empty cell means we must lookAhead
318− content <- (manyTill inline (try $ lookAhead (cellEnd)))
317+ content <- manyTill inline (try $ lookAhead cellEnd)
319 rightSpaces <- length <$> many space
318 rightSpaces <- length <$> many space
320 let align =
319 let align =
321 case compare leftSpaces rightSpaces of
320 case compare leftSpaces rightSpaces of
@@ -323,9 +322,9 @@ tableCell = try $ do
323 EQ -> AlignCenter
322 EQ -> AlignCenter
324 GT -> AlignRight
323 GT -> AlignRight
325 endOfCell
324 endOfCell
326− return $ (align, B.plain (B.trimInlines $ mconcat content))
325+ return (align, B.plain (B.trimInlines $ mconcat content))
327 where
326 where
328− cellEnd = (void newline <|> (many1 space *> endOfCell))
327+ cellEnd = void newline <|> (many1 space *> endOfCell)
329
328
330endOfCell :: T2T ()
329endOfCell :: T2T ()
331endOfCell = try (skipMany1 $ char '|') <|> ( () <$ lookAhead newline)
330endOfCell = try (skipMany1 $ char '|') <|> ( () <$ lookAhead newline)
@@ -348,10 +347,10 @@ taggedBlock = do
348genericBlock :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
347genericBlock :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
349genericBlock p f s = blockMarkupArea p f s <|> blockMarkupLine p f s
348genericBlock p f s = blockMarkupArea p f s <|> blockMarkupLine p f s
350
349
351−blockMarkupArea :: Monoid a => (T2T a) -> (a -> Blocks) -> String -> T2T Blocks
350+blockMarkupArea :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
352−blockMarkupArea p f s = try $ (do
351+blockMarkupArea p f s = try (do
353 string s *> blankline
352 string s *> blankline
354− f . mconcat <$> (manyTill p (eof <|> void (string s *> blankline))))
353+ f . mconcat <$> manyTill p (eof <|> void (string s *> blankline)))
355
354
356blockMarkupLine :: T2T a -> (a -> Blocks) -> String -> T2T Blocks
355blockMarkupLine :: T2T a -> (a -> Blocks) -> String -> T2T Blocks
357blockMarkupLine p f s = try (f <$> (string s *> space *> p))
356blockMarkupLine p f s = try (f <$> (string s *> space *> p))
@@ -369,7 +368,7 @@ parseInlines :: T2T Inlines
369parseInlines = trimInlines . mconcat <$> many1 inline
368parseInlines = trimInlines . mconcat <$> many1 inline
370
369
371inline :: T2T Inlines
370inline :: T2T Inlines
372−inline = do
371+inline =
373 choice
372 choice
374 [ endline
373 [ endline
375 , macro
374 , macro
@@ -391,16 +390,16 @@ inline = do
391 ]
390 ]
392
391
393bold :: T2T Inlines
392bold :: T2T Inlines
394−bold = inlineMarkup inline B.strong '*' (B.str)
393+bold = inlineMarkup inline B.strong '*' B.str
395
394
396underline :: T2T Inlines
395underline :: T2T Inlines
397−underline = inlineMarkup inline underlineSpan '_' (B.str)
396+underline = inlineMarkup inline underlineSpan '_' B.str
398
397
399strike :: T2T Inlines
398strike :: T2T Inlines
400−strike = inlineMarkup inline B.strikeout '-' (B.str)
399+strike = inlineMarkup inline B.strikeout '-' B.str
401
400
402italic :: T2T Inlines
401italic :: T2T Inlines
403−italic = inlineMarkup inline B.emph '/' (B.str)
402+italic = inlineMarkup inline B.emph '/' B.str
404
403
405code :: T2T Inlines
404code :: T2T Inlines
406code = inlineMarkup ((:[]) <$> anyChar) B.code '`' id
405code = inlineMarkup ((:[]) <$> anyChar) B.code '`' id
@@ -419,7 +418,7 @@ tagged = do
419-- Glued meaning that markup must be tight to content
418-- Glued meaning that markup must be tight to content
420-- Markup can't pass newlines
419-- Markup can't pass newlines
421inlineMarkup :: Monoid a
420inlineMarkup :: Monoid a
422− => (T2T a) -- Content parser
421+ => T2T a -- Content parser
423 -> (a -> Inlines) -- Constructor
422 -> (a -> Inlines) -- Constructor
424 -> Char -- Fence
423 -> Char -- Fence
425 -> (String -> a) -- Special Case to handle ******
424 -> (String -> a) -- Special Case to handle ******
@@ -431,7 +430,7 @@ inlineMarkup p f c special = try $ do
431 when (l == 2) (void $ notFollowedBy space)
430 when (l == 2) (void $ notFollowedBy space)
432 -- We must make sure that there is no space before the start of the
431 -- We must make sure that there is no space before the start of the
433 -- closing tags
432 -- closing tags
434− body <- optionMaybe (try $ manyTill (noneOf "\n\r") $
433+ body <- optionMaybe (try $ manyTill (noneOf "\n\r")
435 (try $ lookAhead (noneOf " " >> string [c,c] )))
434 (try $ lookAhead (noneOf " " >> string [c,c] )))
436 case body of
435 case body of
437 Just middle -> do
436 Just middle -> do
@@ -448,7 +447,7 @@ inlineMarkup p f c special = try $ do
448 return $ f (start' <> body' <> end')
447 return $ f (start' <> body' <> end')
449 Nothing -> do -- Either bad or case such as *****
448 Nothing -> do -- Either bad or case such as *****
450 guard (l >= 5)
449 guard (l >= 5)
451− let body' = (replicate (l - 4) c)
450+ let body' = replicate (l - 4) c
452 return $ f (special body')
451 return $ f (special body')
453
452
454link :: T2T Inlines
453link :: T2T Inlines
@@ -463,7 +462,7 @@ titleLink = try $ do
463 guard (length tokens >= 2)
462 guard (length tokens >= 2)
464 char ']'
463 char ']'
465 let link' = last tokens
464 let link' = last tokens
466− guard (length link' > 0)
465+ guard $ not $ null link'
467 let tit = concat (intersperse " " (init tokens))
466 let tit = concat (intersperse " " (init tokens))
468 return $ B.link link' "" (B.text tit)
467 return $ B.link link' "" (B.text tit)
469
468
@@ -489,7 +488,7 @@ macro = try $ do
489-- raw URLs in text are automatically linked
488-- raw URLs in text are automatically linked
490url :: T2T Inlines
489url :: T2T Inlines
491url = try $ do
490url = try $ do
492− (rawUrl, escapedUrl) <- (try uri <|> emailAddress)
491+ (rawUrl, escapedUrl) <- try uri <|> emailAddress
493 return $ B.link rawUrl "" (B.str escapedUrl)
492 return $ B.link rawUrl "" (B.str escapedUrl)
494
493
495uri :: T2T (String, String)
494uri :: T2T (String, String)
@@ -563,8 +562,7 @@ endline = try $ do
563 return B.softbreak
562 return B.softbreak
564
563
565str :: T2T Inlines
564str :: T2T Inlines
566−str = try $ do
567− B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
565+str = try $ B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
568
566
569whitespace :: T2T Inlines
567whitespace :: T2T Inlines
570whitespace = try $ B.space <$ spaceChar
568whitespace = try $ B.space <$ spaceChar