git.iko.soy/typeable/pandoc
on master help sign in
Txt2Tags reader: hlint
commit6e832a571b4357dbaaf57c0cdaf44cb2ea9c4144 authorAlexander Krotov <ilabdsf@gmail.com> dateFri 10 Nov 2017, 14:48 (9 years ago) parent207b3ed
1 file changed+25−27
src/Text/Pandoc/Readers/Txt2Tags.hs+25−27
src/Text/Pandoc/Readers/Txt2Tags.hs+25−27
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ViewPatterns #-}
21{-
32Copyright (C) 2014 Matthew Pickering <matthewtpickering@gmail.com>
43
@@ -94,7 +93,7 @@ readTxt2Tags opts s = do
9493 readWithM parseT2T (def {stateOptions = opts}) $
9594 T.unpack (crFilter s) ++ "\n\n"
9695 case parsed of
97− Right result -> return $ result
96+ Right result -> return result
9897 Left e -> throwError e
9998
10099-- | Read Txt2Tags (ignoring all macros) from an input string returning
@@ -149,7 +148,7 @@ setting = do
149148 string "%!"
150149 keyword <- ignoreSpacesCap (many1 alphaNum)
151150 char ':'
152− value <- ignoreSpacesCap (manyTill anyChar (newline))
151+ value <- ignoreSpacesCap (manyTill anyChar newline)
153152 return (keyword, value)
154153
155154-- Blocks
@@ -158,7 +157,7 @@ parseBlocks :: T2T Blocks
158157parseBlocks = mconcat <$> manyTill block eof
159158
160159block :: T2T Blocks
161−block = do
160+block =
162161 choice
163162 [ mempty <$ blanklines
164163 , quote
@@ -196,7 +195,7 @@ para = try $ do
196195 listStart = try bulletListStart <|> orderedListStart
197196
198197commentBlock :: T2T Blocks
199−commentBlock = try (blockMarkupArea (anyLine) (const mempty) "%%%") <|> comment
198+commentBlock = try (blockMarkupArea anyLine (const mempty) "%%%") <|> comment
200199
201200-- Seperator and Strong line treated the same
202201hrule :: T2T Blocks
@@ -230,7 +229,7 @@ orderedList = B.orderedList . compactify
230229 <$> many1 (listItem orderedListStart parseBlocks)
231230
232231definitionList :: T2T Blocks
233−definitionList = try $ do
232+definitionList = try $
234233 B.definitionList . compactifyDL <$>
235234 many1 (listItem definitionListStart definitionListEnd)
236235
@@ -282,17 +281,17 @@ table = try $ do
282281 rows <- many1 (many commentLine *> tableRow)
283282 let columns = transpose rows
284283 let ncolumns = length columns
285− let aligns = map (foldr1 findAlign) (map (map fst) columns)
284+ let aligns = map (foldr1 findAlign . map fst) columns
286285 let rows' = map (map snd) rows
287286 let size = maximum (map length rows')
288287 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
290289 return $ B.table mempty
291290 (zip aligns (replicate ncolumns 0.0))
292291 headerPadded rowsPadded
293292
294293pad :: (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
296295
297296
298297findAlign :: Alignment -> Alignment -> Alignment
@@ -315,7 +314,7 @@ genericRow start = try $ do
315314tableCell :: T2T (Alignment, Blocks)
316315tableCell = try $ do
317316 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)
319318 rightSpaces <- length <$> many space
320319 let align =
321320 case compare leftSpaces rightSpaces of
@@ -323,9 +322,9 @@ tableCell = try $ do
323322 EQ -> AlignCenter
324323 GT -> AlignRight
325324 endOfCell
326− return $ (align, B.plain (B.trimInlines $ mconcat content))
325+ return (align, B.plain (B.trimInlines $ mconcat content))
327326 where
328− cellEnd = (void newline <|> (many1 space *> endOfCell))
327+ cellEnd = void newline <|> (many1 space *> endOfCell)
329328
330329endOfCell :: T2T ()
331330endOfCell = try (skipMany1 $ char '|') <|> ( () <$ lookAhead newline)
@@ -348,10 +347,10 @@ taggedBlock = do
348347genericBlock :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
349348genericBlock p f s = blockMarkupArea p f s <|> blockMarkupLine p f s
350349
351−blockMarkupArea :: Monoid a => (T2T a) -> (a -> Blocks) -> String -> T2T Blocks
352−blockMarkupArea p f s = try $ (do
350+blockMarkupArea :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
351+blockMarkupArea p f s = try (do
353352 string s *> blankline
354− f . mconcat <$> (manyTill p (eof <|> void (string s *> blankline))))
353+ f . mconcat <$> manyTill p (eof <|> void (string s *> blankline)))
355354
356355blockMarkupLine :: T2T a -> (a -> Blocks) -> String -> T2T Blocks
357356blockMarkupLine p f s = try (f <$> (string s *> space *> p))
@@ -369,7 +368,7 @@ parseInlines :: T2T Inlines
369368parseInlines = trimInlines . mconcat <$> many1 inline
370369
371370inline :: T2T Inlines
372−inline = do
371+inline =
373372 choice
374373 [ endline
375374 , macro
@@ -391,16 +390,16 @@ inline = do
391390 ]
392391
393392bold :: T2T Inlines
394−bold = inlineMarkup inline B.strong '*' (B.str)
393+bold = inlineMarkup inline B.strong '*' B.str
395394
396395underline :: T2T Inlines
397−underline = inlineMarkup inline underlineSpan '_' (B.str)
396+underline = inlineMarkup inline underlineSpan '_' B.str
398397
399398strike :: T2T Inlines
400−strike = inlineMarkup inline B.strikeout '-' (B.str)
399+strike = inlineMarkup inline B.strikeout '-' B.str
401400
402401italic :: T2T Inlines
403−italic = inlineMarkup inline B.emph '/' (B.str)
402+italic = inlineMarkup inline B.emph '/' B.str
404403
405404code :: T2T Inlines
406405code = inlineMarkup ((:[]) <$> anyChar) B.code '`' id
@@ -419,7 +418,7 @@ tagged = do
419418-- Glued meaning that markup must be tight to content
420419-- Markup can't pass newlines
421420inlineMarkup :: Monoid a
422− => (T2T a) -- Content parser
421+ => T2T a -- Content parser
423422 -> (a -> Inlines) -- Constructor
424423 -> Char -- Fence
425424 -> (String -> a) -- Special Case to handle ******
@@ -431,7 +430,7 @@ inlineMarkup p f c special = try $ do
431430 when (l == 2) (void $ notFollowedBy space)
432431 -- We must make sure that there is no space before the start of the
433432 -- closing tags
434− body <- optionMaybe (try $ manyTill (noneOf "\n\r") $
433+ body <- optionMaybe (try $ manyTill (noneOf "\n\r")
435434 (try $ lookAhead (noneOf " " >> string [c,c] )))
436435 case body of
437436 Just middle -> do
@@ -448,7 +447,7 @@ inlineMarkup p f c special = try $ do
448447 return $ f (start' <> body' <> end')
449448 Nothing -> do -- Either bad or case such as *****
450449 guard (l >= 5)
451− let body' = (replicate (l - 4) c)
450+ let body' = replicate (l - 4) c
452451 return $ f (special body')
453452
454453link :: T2T Inlines
@@ -463,7 +462,7 @@ titleLink = try $ do
463462 guard (length tokens >= 2)
464463 char ']'
465464 let link' = last tokens
466− guard (length link' > 0)
465+ guard $ not $ null link'
467466 let tit = concat (intersperse " " (init tokens))
468467 return $ B.link link' "" (B.text tit)
469468
@@ -489,7 +488,7 @@ macro = try $ do
489488-- raw URLs in text are automatically linked
490489url :: T2T Inlines
491490url = try $ do
492− (rawUrl, escapedUrl) <- (try uri <|> emailAddress)
491+ (rawUrl, escapedUrl) <- try uri <|> emailAddress
493492 return $ B.link rawUrl "" (B.str escapedUrl)
494493
495494uri :: T2T (String, String)
@@ -563,8 +562,7 @@ endline = try $ do
563562 return B.softbreak
564563
565564str :: T2T Inlines
566−str = try $ do
567− B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
565+str = try $ B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
568566
569567whitespace :: T2T Inlines
570568whitespace = try $ B.space <$ spaceChar