git.iko.soy/typeable/pandoc
on master help sign in
More hlint.
commit271e1fe2f1c41ff177807a86ead47e2d70d69c55 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 29 Oct 2017, 13:19 (9 years ago) parent218d212
3 files changed+30−33
src/Text/Pandoc/Writers/AsciiDoc.hs+12−13 src/Text/Pandoc/Writers/CommonMark.hs+6−6 src/Text/Pandoc/Writers/ConTeXt.hs+12−14
src/Text/Pandoc/Writers/AsciiDoc.hs+12−13
@@ -42,7 +42,7 @@ import Data.Aeson (Result (..), Value (String), fromJSON, toJSON)
4242import Data.Char (isPunctuation, isSpace)
4343import Data.List (intercalate, intersperse, stripPrefix)
4444import qualified Data.Map as M
45−import Data.Maybe (fromMaybe)
45+import Data.Maybe (fromMaybe, isJust)
4646import Data.Text (Text)
4747import qualified Data.Text as T
4848import Text.Pandoc.Class (PandocMonad, report)
@@ -100,9 +100,8 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
100100 let context = defField "body" main
101101 $ defField "toc"
102102 (writerTableOfContents opts &&
103− writerTemplate opts /= Nothing)
104− $ defField "titleblock" titleblock
105− $ metadata'
103+ Data.Maybe.isJust (writerTemplate opts))
104+ $defField "titleblock" titleblock metadata'
106105 case writerTemplate opts of
107106 Nothing -> return main
108107 Just tpl -> renderTemplate' tpl context
@@ -137,7 +136,7 @@ blockToAsciiDoc _ Null = return empty
137136blockToAsciiDoc opts (Plain inlines) = do
138137 contents <- inlineListToAsciiDoc opts inlines
139138 return $ contents <> blankline
140−blockToAsciiDoc opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) = do
139+blockToAsciiDoc opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
141140 blockToAsciiDoc opts (Para [Image attr alt (src,tit)])
142141blockToAsciiDoc opts (Para inlines) = do
143142 contents <- inlineListToAsciiDoc opts inlines
@@ -165,9 +164,9 @@ blockToAsciiDoc opts (Header level (ident,_,_) inlines) = do
165164 let len = offset contents
166165 -- ident seem to be empty most of the time and asciidoc will generate them automatically
167166 -- so lets make them not show up when null
168− let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
167+ let identifier = if null ident then empty else "[[" <> text ident <> "]]"
169168 let setext = writerSetextHeaders opts
170− return $
169+ return
171170 (if setext
172171 then
173172 identifier $$ contents $$
@@ -179,7 +178,7 @@ blockToAsciiDoc opts (Header level (ident,_,_) inlines) = do
179178 _ -> empty) <> blankline
180179 else
181180 identifier $$ text (replicate level '=') <> space <> contents <> blankline)
182−blockToAsciiDoc _ (CodeBlock (_,classes,_) str) = return $ (flush $
181+blockToAsciiDoc _ (CodeBlock (_,classes,_) str) = return $ flush (
183182 if null classes
184183 then "...." $$ text str $$ "...."
185184 else attrs $$ "----" $$ text str $$ "----")
@@ -204,7 +203,7 @@ blockToAsciiDoc opts (Table caption aligns widths headers rows) = do
204203 let isSimple = all (== 0) widths
205204 let relativePercentWidths = if isSimple
206205 then widths
207− else map (/ (sum widths)) widths
206+ else map (/ sum widths) widths
208207 let widths'' :: [Integer]
209208 widths'' = map (floor . (* 100)) relativePercentWidths
210209 -- ensure that the widths sum to 100
@@ -266,14 +265,14 @@ blockToAsciiDoc opts (OrderedList (_start, sty, _delim) items) = do
266265 let markers' = map (\m -> if length m < 3
267266 then m ++ replicate (3 - length m) ' '
268267 else m) markers
269− contents <- mapM (\(item, num) -> orderedListItemToAsciiDoc opts item num) $
268+ contents <- mapM (uncurry (orderedListItemToAsciiDoc opts)) $
270269 zip markers' items
271270 return $ cat contents <> blankline
272271blockToAsciiDoc opts (DefinitionList items) = do
273272 contents <- mapM (definitionListItemToAsciiDoc opts) items
274273 return $ cat contents <> blankline
275274blockToAsciiDoc opts (Div (ident,_,_) bs) = do
276− let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
275+ let identifier = if null ident then empty else ("[[" <> text ident <> "]]")
277276 contents <- blockListToAsciiDoc opts bs
278277 return $ identifier $$ contents
279278
@@ -460,7 +459,7 @@ inlineToAsciiDoc opts (Image attr alternate (src, tit)) = do
460459 let linktitle = if null tit
461460 then empty
462461 else ",title=\"" <> text tit <> "\""
463− showDim dir = case (dimension dir attr) of
462+ showDim dir = case dimension dir attr of
464463 Just (Percent a) ->
465464 ["scaledwidth=" <> text (show (Percent a))]
466465 Just dim ->
@@ -480,6 +479,6 @@ inlineToAsciiDoc opts (Note [Plain inlines]) = do
480479-- asciidoc can't handle blank lines in notes
481480inlineToAsciiDoc _ (Note _) = return "[multiblock footnote omitted]"
482481inlineToAsciiDoc opts (Span (ident,_,_) ils) = do
483− let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
482+ let identifier = if null ident then empty else ("[[" <> text ident <> "]]")
484483 contents <- inlineListToAsciiDoc opts ils
485484 return $ identifier <> contents
src/Text/Pandoc/Writers/CommonMark.hs+6−6
@@ -60,7 +60,7 @@ writeCommonMark opts (Pandoc meta blocks) = do
6060 (blocksToCommonMark opts)
6161 (inlinesToCommonMark opts)
6262 meta
63− let context = defField "body" main $ metadata
63+ let context = defField "body" main metadata
6464 case writerTemplate opts of
6565 Nothing -> return main
6666 Just tpl -> renderTemplate' tpl context
@@ -108,11 +108,11 @@ blockToNodes opts (Plain xs) ns =
108108blockToNodes opts (Para xs) ns =
109109 return (node PARAGRAPH (inlinesToNodes opts xs) : ns)
110110blockToNodes opts (LineBlock lns) ns = blockToNodes opts (linesToPara lns) ns
111−blockToNodes _ (CodeBlock (_,classes,_) xs) ns = return $
111+blockToNodes _ (CodeBlock (_,classes,_) xs) ns = return
112112 (node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] : ns)
113113blockToNodes _ (RawBlock fmt xs) ns
114114 | fmt == Format "html" = return (node (HTML_BLOCK (T.pack xs)) [] : ns)
115− | otherwise = return (node (CUSTOM_BLOCK (T.pack xs) (T.empty)) [] : ns)
115+ | otherwise = return (node (CUSTOM_BLOCK (T.pack xs) T.empty) [] : ns)
116116blockToNodes opts (BlockQuote bs) ns = do
117117 nodes <- blocksToNodes opts bs
118118 return (node BLOCK_QUOTE nodes : ns)
@@ -142,9 +142,9 @@ blockToNodes opts (Div _ bs) ns = do
142142blockToNodes opts (DefinitionList items) ns =
143143 blockToNodes opts (BulletList items') ns
144144 where items' = map dlToBullet items
145− dlToBullet (term, ((Para xs : ys) : zs)) =
145+ dlToBullet (term, (Para xs : ys) : zs) =
146146 Para (term ++ [LineBreak] ++ xs) : ys ++ concat zs
147− dlToBullet (term, ((Plain xs : ys) : zs)) =
147+ dlToBullet (term, (Plain xs : ys) : zs) =
148148 Plain (term ++ [LineBreak] ++ xs) : ys ++ concat zs
149149 dlToBullet (term, xs) =
150150 Para term : concat xs
@@ -264,7 +264,7 @@ inlineToNodes opts (Image _ ils (url,tit)) =
264264 (node (IMAGE (T.pack url) (T.pack tit)) (inlinesToNodes opts ils) :)
265265inlineToNodes _ (RawInline fmt xs)
266266 | fmt == Format "html" = (node (HTML_INLINE (T.pack xs)) [] :)
267− | otherwise = (node (CUSTOM_INLINE (T.pack xs) (T.empty)) [] :)
267+ | otherwise = (node (CUSTOM_INLINE (T.pack xs) T.empty) [] :)
268268inlineToNodes opts (Quoted qt ils) =
269269 ((node (TEXT start) [] :
270270 inlinesToNodes opts ils ++ [node (TEXT end) []]) ++)
src/Text/Pandoc/Writers/ConTeXt.hs+12−14
@@ -33,7 +33,7 @@ module Text.Pandoc.Writers.ConTeXt ( writeConTeXt ) where
3333import Control.Monad.State.Strict
3434import Data.Char (ord)
3535import Data.List (intercalate, intersperse)
36−import Data.Maybe (catMaybes)
36+import Data.Maybe (mapMaybe)
3737import Data.Text (Text)
3838import Network.URI (unEscapeString)
3939import Text.Pandoc.BCP47
@@ -82,8 +82,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
8282 meta
8383 body <- mapM (elementToConTeXt options) $ hierarchicalize blocks
8484 let main = (render' . vcat) body
85− let layoutFromMargins = intercalate [','] $ catMaybes $
86− map (\(x,y) ->
85+ let layoutFromMargins = intercalate [','] $ mapMaybe (\(x,y) ->
8786 ((x ++ "=") ++) <$> getField y metadata)
8887 [("leftmargin","margin-left")
8988 ,("rightmargin","margin-right")
@@ -107,8 +106,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
107106 $ (case getField "papersize" metadata of
108107 Just ("a4" :: String) -> resetField "papersize"
109108 ("A4" :: String)
110− _ -> id)
111− $ metadata
109+ _ -> id) metadata
112110 let context' = defField "context-dir" (toContextDir
113111 $ getField "dir" context) context
114112 case writerTemplate options of
@@ -150,7 +148,7 @@ stringToConTeXt opts = concatMap (escapeCharForConTeXt opts)
150148toLabel :: String -> String
151149toLabel z = concatMap go z
152150 where go x
153− | elem x ("\\#[]\",{}%()|=" :: String) = "ux" ++ printf "%x" (ord x)
151+ | x `elem` ("\\#[]\",{}%()|=" :: String) = "ux" ++ printf "%x" (ord x)
154152 | otherwise = [x]
155153
156154-- | Convert Elements to ConTeXt
@@ -206,7 +204,7 @@ blockToConTeXt (Div (ident,_,kvs) bs) = do
206204 <> text lng <> "]" $$ txt $$ "\\stop"
207205 Nothing -> txt
208206 wrapBlank txt = blankline <> txt <> blankline
209− fmap (wrapBlank . wrapLang . wrapDir . wrapRef) $ blockListToConTeXt bs
207+ (wrapBlank . wrapLang . wrapDir . wrapRef) <$> blockListToConTeXt bs
210208blockToConTeXt (BulletList lst) = do
211209 contents <- mapM listItemToConTeXt lst
212210 return $ ("\\startitemize" <> if isTightList lst
@@ -261,7 +259,7 @@ blockToConTeXt (Table caption aligns widths heads rows) = do
261259 if colWidth == 0
262260 then "|"
263261 else ("p(" ++ printf "%.2f" colWidth ++ "\\textwidth)|")
264− let colDescriptors = "|" ++ (concat $
262+ let colDescriptors = "|" ++ concat (
265263 zipWith colDescriptor widths aligns)
266264 headers <- if all null heads
267265 then return empty
@@ -279,11 +277,11 @@ blockToConTeXt (Table caption aligns widths heads rows) = do
279277tableRowToConTeXt :: PandocMonad m => [[Block]] -> WM m Doc
280278tableRowToConTeXt cols = do
281279 cols' <- mapM blockListToConTeXt cols
282− return $ (vcat (map ("\\NC " <>) cols')) $$ "\\NC\\AR"
280+ return $ vcat (map ("\\NC " <>) cols') $$ "\\NC\\AR"
283281
284282listItemToConTeXt :: PandocMonad m => [Block] -> WM m Doc
285283listItemToConTeXt list = blockListToConTeXt list >>=
286− return . ("\\item" $$) . (nest 2)
284+ return . ("\\item" $$) . nest 2
287285
288286defListItemToConTeXt :: PandocMonad m => ([Inline], [[Block]]) -> WM m Doc
289287defListItemToConTeXt (term, defs) = do
@@ -358,7 +356,7 @@ inlineToConTeXt (RawInline "tex" str) = return $ text str
358356inlineToConTeXt il@(RawInline _ _) = do
359357 report $ InlineNotRendered il
360358 return empty
361−inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
359+inlineToConTeXt LineBreak = return $ text "\\crlf" <> cr
362360inlineToConTeXt SoftBreak = do
363361 wrapText <- gets (writerWrapText . stOptions)
364362 return $ case wrapText of
@@ -367,7 +365,7 @@ inlineToConTeXt SoftBreak = do
367365 WrapPreserve -> cr
368366inlineToConTeXt Space = return space
369367-- Handle HTML-like internal document references to sections
370−inlineToConTeXt (Link _ txt (('#' : ref), _)) = do
368+inlineToConTeXt (Link _ txt ('#' : ref, _)) = do
371369 opts <- gets stOptions
372370 contents <- inlineListToConTeXt txt
373371 let ref' = toLabel $ stringToConTeXt opts ref
@@ -393,7 +391,7 @@ inlineToConTeXt (Link _ txt (src, _)) = do
393391inlineToConTeXt (Image attr@(_,cls,_) _ (src, _)) = do
394392 opts <- gets stOptions
395393 let showDim dir = let d = text (show dir) <> "="
396− in case (dimension dir attr) of
394+ in case dimension dir attr of
397395 Just (Pixel a) ->
398396 [d <> text (showInInch opts (Pixel a)) <> "in"]
399397 Just (Percent a) ->
@@ -432,7 +430,7 @@ inlineToConTeXt (Span (_,_,kvs) ils) = do
432430 Just lng -> "\\start\\language[" <> text lng
433431 <> "]" <> txt <> "\\stop "
434432 Nothing -> txt
435− fmap (wrapLang . wrapDir) $ inlineListToConTeXt ils
433+ (wrapLang . wrapDir) <$> inlineListToConTeXt ils
436434
437435-- | Craft the section header, inserting the section reference, if supplied.
438436sectionHeader :: PandocMonad m