git.iko.soy/typeable/pandoc
on master help sign in
hlint changes.
commitb201a8aa582e1146243796fac26e57579af55f5f authorJohn MacFarlane <jgm@berkeley.edu> dateFri 27 Oct 2017, 21:29 (9 years ago) parentf3e901c
9 files changed+118−126
src/Text/Pandoc/MediaBag.hs+1−1 src/Text/Pandoc/PDF.hs+3−5 src/Text/Pandoc/Pretty.hs+16−20 src/Text/Pandoc/Readers/CommonMark.hs+2−2 src/Text/Pandoc/Readers/Creole.hs+19−17 src/Text/Pandoc/Readers/DocBook.hs+22−18 src/Text/Pandoc/Readers/Docx/Combine.hs+12−12 src/Text/Pandoc/Readers/Docx/Lists.hs+30−38 src/Text/Pandoc/Readers/Docx/Parse.hs+13−13
src/Text/Pandoc/MediaBag.hs+1−1
@@ -80,4 +80,4 @@ lookupMedia fp (MediaBag mediamap) = M.lookup (splitDirectories fp) mediamap
8080mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
8181mediaDirectory (MediaBag mediamap) =
8282 M.foldrWithKey (\fp (mime,contents) ->
83− (((Posix.joinPath fp), mime, fromIntegral $ BL.length contents):)) [] mediamap
83+ ((Posix.joinPath fp, mime, fromIntegral $ BL.length contents):)) [] mediamap
src/Text/Pandoc/PDF.hs+3−5
@@ -327,7 +327,7 @@ ms2pdf verbosity args source = do
327327 putStrLn "[makePDF] Environment:"
328328 mapM_ print env'
329329 putStr "\n"
330− putStrLn $ "[makePDF] Contents:\n"
330+ putStrLn "[makePDF] Contents:\n"
331331 putStr $ T.unpack source
332332 putStr "\n"
333333 (exit, out) <- E.catch
@@ -351,9 +351,7 @@ html2pdf :: Verbosity -- ^ Verbosity level
351351 -> IO (Either ByteString ByteString)
352352html2pdf verbosity program args source = do
353353 pdfFile <- withTempFile "." "html2pdf.pdf" $ \fp _ -> return fp
354− let pdfFileArgName = if program == "prince"
355− then ["-o"]
356− else []
354+ let pdfFileArgName = ["-o" | program == "prince"]
357355 let programArgs = args ++ ["-"] ++ pdfFileArgName ++ [pdfFile]
358356 env' <- getEnvironment
359357 when (verbosity >= INFO) $ do
@@ -363,7 +361,7 @@ html2pdf verbosity program args source = do
363361 putStrLn "[makePDF] Environment:"
364362 mapM_ print env'
365363 putStr "\n"
366− putStrLn $ "[makePDF] Contents of intermediate HTML:"
364+ putStrLn "[makePDF] Contents of intermediate HTML:"
367365 TextIO.putStr source
368366 putStr "\n"
369367 (exit, out) <- E.catch
src/Text/Pandoc/Pretty.hs+16−20
@@ -78,6 +78,7 @@ module Text.Pandoc.Pretty (
7878
7979where
8080import Control.Monad.State.Strict
81+import Control.Monad (when)
8182import Data.Char (isSpace)
8283import Data.Foldable (toList)
8384import Data.List (intersperse)
@@ -144,11 +145,10 @@ hcat = mconcat
144145-- between them.
145146infixr 6 <+>
146147(<+>) :: Doc -> Doc -> Doc
147−(<+>) x y = if isEmpty x
148− then y
149− else if isEmpty y
150− then x
151− else x <> space <> y
148+(<+>) x y
149+ | isEmpty x = y
150+ | isEmpty y = x
151+ | otherwise = x <> space <> y
152152
153153-- | Same as 'cat', but putting breakable spaces between the
154154-- 'Doc's.
@@ -158,20 +158,18 @@ hsep = foldr (<+>) empty
158158infixr 5 $$
159159-- | @a $$ b@ puts @a@ above @b@.
160160($$) :: Doc -> Doc -> Doc
161−($$) x y = if isEmpty x
162− then y
163− else if isEmpty y
164− then x
165− else x <> cr <> y
161+($$) x y
162+ | isEmpty x = y
163+ | isEmpty y = x
164+ | otherwise = x <> cr <> y
166165
167166infixr 5 $+$
168167-- | @a $+$ b@ puts @a@ above @b@, with a blank line between.
169168($+$) :: Doc -> Doc -> Doc
170−($+$) x y = if isEmpty x
171− then y
172− else if isEmpty y
173− then x
174− else x <> blankline <> y
169+($+$) x y
170+ | isEmpty x = y
171+ | isEmpty y = x
172+ | otherwise = x <> blankline <> y
175173
176174-- | List version of '$$'.
177175vcat :: [Doc] -> Doc
@@ -217,9 +215,9 @@ outp off s | off < 0 = do -- offset < 0 means newline characters
217215outp off s = do -- offset >= 0 (0 might be combining char)
218216 st' <- get
219217 let pref = prefix st'
220− when (column st' == 0 && usePrefix st' && not (null pref)) $ do
218+ when (column st' == 0 && usePrefix st' && not (null pref)) $
221219 modify $ \st -> st{ output = fromString pref : output st
222− , column = column st + realLength pref }
220+ , column = column st + realLength pref }
223221 modify $ \st -> st{ output = fromString s : output st
224222 , column = column st + off
225223 , newlines = 0 }
@@ -328,9 +326,7 @@ renderList (BreakingSpace : xs) = do
328326
329327renderList (AfterBreak s : xs) = do
330328 st <- get
331− if newlines st > 0
332− then outp (realLength s) s
333− else return ()
329+ when (newlines st > 0) $ outp (realLength s) s
334330 renderList xs
335331
336332renderList (Block i1 s1 : Block i2 s2 : xs) =
src/Text/Pandoc/Readers/CommonMark.hs+2−2
@@ -132,12 +132,12 @@ addBlock opts (Node _ (LIST listAttrs) nodes) =
132132 setTightness = if listTight listAttrs
133133 then map paraToPlain
134134 else id
135− paraToPlain (Para xs) = Plain (xs)
135+ paraToPlain (Para xs) = Plain xs
136136 paraToPlain x = x
137137 delim = case listDelim listAttrs of
138138 PERIOD_DELIM -> Period
139139 PAREN_DELIM -> OneParen
140−addBlock opts (Node _ (TABLE alignments) nodes) = do
140+addBlock opts (Node _ (TABLE alignments) nodes) =
141141 (Table [] aligns widths headers rows :)
142142 where aligns = map fromTableCellAlignment alignments
143143 fromTableCellAlignment NoAlignment = AlignDefault
src/Text/Pandoc/Readers/Creole.hs+19−17
@@ -111,7 +111,7 @@ block = do
111111 return res
112112
113113nowiki :: PandocMonad m => CRLParser m B.Blocks
114−nowiki = try $ nowikiStart >> manyTill content nowikiEnd >>= return . B.codeBlock . mconcat
114+nowiki = try $ fmap (B.codeBlock . mconcat) (nowikiStart >> manyTill content nowikiEnd)
115115 where
116116 content = brackets <|> line
117117 brackets = try $ option "" ((:[]) <$> newline)
@@ -124,7 +124,8 @@ nowiki = try $ nowikiStart >> manyTill content nowikiEnd >>= return . B.codeBloc
124124header :: PandocMonad m => CRLParser m B.Blocks
125125header = try $ do
126126 skipSpaces
127− level <- many1 (char '=') >>= return . length
127+ level <-
128+ fmap length (many1 (char '='))
128129 guard $ level <= 6
129130 skipSpaces
130131 content <- B.str <$> manyTill (noneOf "\n") headerEnd
@@ -145,16 +146,16 @@ anyListItem :: PandocMonad m => Int -> CRLParser m B.Blocks
145146anyListItem n = listItem '*' n <|> listItem '#' n
146147
147148list :: PandocMonad m => Char -> ([B.Blocks] -> B.Blocks) -> Int -> CRLParser m B.Blocks
148−list c f n = many1 (itemPlusSublist <|> listItem c n)
149− >>= return . f
149+list c f n =
150+ fmap f (many1 (itemPlusSublist <|> listItem c n))
150151 where itemPlusSublist = try $ listItem c n <+> anyList (n+1)
151152
152153listItem :: PandocMonad m => Char -> Int -> CRLParser m B.Blocks
153−listItem c n = (listStart >> many1Till inline itemEnd)
154− >>= return . B.plain . B.trimInlines .mconcat
154+listItem c n =
155+ fmap (B.plain . B.trimInlines .mconcat) (listStart >> many1Till inline itemEnd)
155156 where
156157 listStart = try $ optional newline >> skipSpaces >> count n (char c)
157− >> (lookAhead $ noneOf [c]) >> skipSpaces
158+ >> lookAhead (noneOf [c]) >> skipSpaces
158159 itemEnd = endOfParaElement <|> nextItem n
159160 <|> if n < 3 then nextItem (n+1)
160161 else nextItem (n+1) <|> nextItem (n-1)
@@ -176,7 +177,7 @@ table = try $ do
176177 cellEnd = lookAhead $ try $ char '|' <|> rowEnd
177178
178179para :: PandocMonad m => CRLParser m B.Blocks
179−para = many1Till inline endOfParaElement >>= return . result . mconcat
180+para = fmap (result . mconcat) (many1Till inline endOfParaElement)
180181 where
181182 result content = if F.all (==Space) content
182183 then mempty
@@ -192,7 +193,7 @@ endOfParaElement = lookAhead $ endOfInput <|> endOfPara
192193 startOf :: PandocMonad m => CRLParser m a -> CRLParser m ()
193194 startOf p = try $ blankline >> p >> return mempty
194195 startOfList = startOf $ anyList 1
195− startOfTable = startOf $ table
196+ startOfTable =startOf table
196197 startOfHeader = startOf header
197198 startOfNowiki = startOf nowiki
198199 hr = startOf horizontalRule
@@ -223,7 +224,8 @@ inline = choice [ whitespace
223224 ] <?> "inline"
224225
225226escapedChar :: PandocMonad m => CRLParser m B.Inlines
226−escapedChar = (try $ char '~' >> noneOf "\t\n ") >>= return . B.str . (:[])
227+escapedChar =
228+ fmap (B.str . (:[])) (try $ char '~' >> noneOf "\t\n ")
227229
228230escapedLink :: PandocMonad m => CRLParser m B.Inlines
229231escapedLink = try $ do
@@ -234,7 +236,7 @@ escapedLink = try $ do
234236image :: PandocMonad m => CRLParser m B.Inlines
235237image = try $ do
236238 (orig, src) <- wikiImg
237− return $ B.image src "" (B.str $ orig)
239+ return $ B.image src "" (B.str orig)
238240 where
239241 linkSrc = many $ noneOf "|}\n\r\t"
240242 linkDsc = char '|' >> many (noneOf "}\n\r\t")
@@ -253,7 +255,7 @@ link = try $ do
253255 linkSrc = many $ noneOf "|]\n\r\t"
254256 linkDsc :: PandocMonad m => String -> CRLParser m B.Inlines
255257 linkDsc otxt = B.str
256− <$> (try $ option otxt
258+ <$> try (option otxt
257259 (char '|' >> many (noneOf "]\n\r\t")))
258260 linkImg = try $ char '|' >> image
259261 wikiLink = try $ do
@@ -270,17 +272,17 @@ inlineNowiki :: PandocMonad m => CRLParser m B.Inlines
270272inlineNowiki = B.code <$> (start >> manyTill (noneOf "\n\r") end)
271273 where
272274 start = try $ string "{{{"
273− end = try $ string "}}}" >> (lookAhead $ noneOf "}")
275+ end = try $ string "}}}" >> lookAhead (noneOf "}")
274276
275277placeholder :: PandocMonad m => CRLParser m B.Inlines
276278-- The semantics of the placeholder is basicallly implementation
277279-- dependent, so there is no way to DTRT for all cases.
278280-- So for now we just drop them.
279−placeholder = B.text <$> (try $ string "<<<" >> manyTill anyChar (string ">>>")
281+placeholder = B.text <$> try (string "<<<" >> manyTill anyChar (string ">>>")
280282 >> return "")
281283
282284whitespace :: PandocMonad m => CRLParser m B.Inlines
283−whitespace = (lb <|> regsp) >>= return
285+whitespace = (lb <|> regsp)
284286 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
285287 regsp = try $ skipMany1 spaceChar >> return B.space
286288
@@ -290,11 +292,11 @@ linebreak = newline >> notFollowedBy newline >> (lastNewline <|> innerNewline)
290292 innerNewline = return B.space
291293
292294symbol :: PandocMonad m => CRLParser m B.Inlines
293−symbol = oneOf specialChars >>= return . B.str . (:[])
295+symbol = fmap (B.str . (:[])) (oneOf specialChars)
294296
295297str :: PandocMonad m => CRLParser m B.Inlines
296298str = let strChar = noneOf ("\t\n " ++ specialChars) in
297− many1 strChar >>= return . B.str
299+ fmap B.str (many1 strChar)
298300
299301bold :: PandocMonad m => CRLParser m B.Inlines
300302bold = B.strong . mconcat <$>
src/Text/Pandoc/Readers/DocBook.hs+22−18
@@ -1,5 +1,5 @@
11module Text.Pandoc.Readers.DocBook ( readDocBook ) where
2−import Data.Char (toUpper)
2+import Data.Char (toUpper, isSpace)
33import Text.Pandoc.Shared (safeRead, crFilter)
44import Text.Pandoc.Options
55import Text.Pandoc.Definition
@@ -8,7 +8,6 @@ import Text.XML.Light
88import Text.HTML.TagSoup.Entity (lookupEntity)
99import Data.Either (rights)
1010import Data.Generics
11−import Data.Char (isSpace)
1211import Control.Monad.State.Strict
1312import Data.List (intersperse)
1413import Data.Maybe (fromMaybe)
@@ -528,7 +527,7 @@ readDocBook :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
528527readDocBook _ inp = do
529528 let tree = normalizeTree . parseXML . handleInstructions
530529 $ T.unpack $ crFilter inp
531− (bs, st') <- flip runStateT (def{ dbContent = tree }) $ mapM parseBlock $ tree
530+ (bs, st') <- flip runStateT (def{ dbContent = tree }) $ mapM parseBlock tree
532531 return $ Pandoc (dbMeta st') (toList . mconcat $ bs)
533532
534533-- We treat <?asciidoc-br?> specially (issue #1236), converting it
@@ -567,14 +566,12 @@ normalizeTree = everywhere (mkT go)
567566 go xs = xs
568567
569568convertEntity :: String -> String
570−convertEntity e = maybe (map toUpper e) id (lookupEntity e)
569+convertEntity e = Data.Maybe.fromMaybe (map toUpper e) (lookupEntity e)
571570
572571-- convenience function to get an attribute value, defaulting to ""
573572attrValue :: String -> Element -> String
574573attrValue attr elt =
575− case lookupAttrBy (\x -> qName x == attr) (elAttribs elt) of
576− Just z -> z
577− Nothing -> ""
574+ fromMaybe "" (lookupAttrBy (\x -> qName x == attr) (elAttribs elt))
578575
579576-- convenience function
580577named :: String -> Element -> Bool
@@ -654,15 +651,17 @@ getMediaobject e = do
654651 || named "textobject" x
655652 || named "alt" x) el of
656653 Nothing -> return mempty
657− Just z -> mconcat <$> (mapM parseInline $ elContent z)
654+ Just z -> mconcat <$>
655+ mapM parseInline (elContent z)
658656 figTitle <- gets dbFigureTitle
659657 let (caption, title) = if isNull figTitle
660658 then (getCaption e, "")
661659 else (return figTitle, "fig:")
662− liftM (imageWith attr imageUrl title) caption
660+ fmap (imageWith attr imageUrl title) caption
663661
664662getBlocks :: PandocMonad m => Element -> DB m Blocks
665−getBlocks e = mconcat <$> (mapM parseBlock $ elContent e)
663+getBlocks e = mconcat <$>
664+ mapM parseBlock (elContent e)
666665
667666
668667parseBlock :: PandocMonad m => Content -> DB m Blocks
@@ -806,7 +805,8 @@ parseBlock (Elem e) =
806805 attrib <- case filterChild (named "attribution") e of
807806 Nothing -> return mempty
808807 Just z -> (para . (str "— " <>) . mconcat)
809− <$> (mapM parseInline $ elContent z)
808+ <$>
809+ mapM parseInline (elContent z)
810810 contents <- getBlocks e
811811 return $ blockQuote (contents <> attrib)
812812 listitems = mapM getBlocks $ filterChildren (named "listitem") e
@@ -906,7 +906,8 @@ parseBlock (Elem e) =
906906 metaBlock = acceptingMetadata (getBlocks e) >> return mempty
907907
908908getInlines :: PandocMonad m => Element -> DB m Inlines
909−getInlines e' = (trimInlines . mconcat) <$> (mapM parseInline $ elContent e')
909+getInlines e' = (trimInlines . mconcat) <$>
910+ mapM parseInline (elContent e')
910911
911912strContentRecursive :: Element -> String
912913strContentRecursive = strContent .
@@ -919,7 +920,7 @@ elementToStr x = x
919920parseInline :: PandocMonad m => Content -> DB m Inlines
920921parseInline (Text (CData _ s _)) = return $ text s
921922parseInline (CRef ref) =
922− return $ maybe (text $ map toUpper ref) (text) $ lookupEntity ref
923+ return $ maybe (text $ map toUpper ref) text $ lookupEntity ref
923924parseInline (Elem e) =
924925 case qName (elName e) of
925926 "equation" -> equation displayMath
@@ -960,8 +961,10 @@ parseInline (Elem e) =
960961 "userinput" -> codeWithLang
961962 "varargs" -> return $ code "(...)"
962963 "keycap" -> return (str $ strContent e)
963− "keycombo" -> keycombo <$> (mapM parseInline $ elContent e)
964− "menuchoice" -> menuchoice <$> (mapM parseInline $
964+ "keycombo" -> keycombo <$>
965+ mapM parseInline (elContent e)
966+ "menuchoice" -> menuchoice <$>
967+ mapM parseInline (
965968 filter isGuiMenu $ elContent e)
966969 "xref" -> do
967970 content <- dbContent <$> get
@@ -980,7 +983,7 @@ parseInline (Elem e) =
980983 ils <- innerInlines
981984 let href = case findAttr (QName "href" (Just "http://www.w3.org/1999/xlink") Nothing) e of
982985 Just h -> h
983− _ -> ('#' : attrValue "linkend" e)
986+ _ -> '#' : attrValue "linkend" e
984987 let ils' = if ils == mempty then str href else ils
985988 let attr = (attrValue "id" e, words $ attrValue "role" e, [])
986989 return $ linkWith attr href "" ils'
@@ -990,7 +993,8 @@ parseInline (Elem e) =
990993 "strong" -> strong <$> innerInlines
991994 "strikethrough" -> strikeout <$> innerInlines
992995 _ -> emph <$> innerInlines
993− "footnote" -> (note . mconcat) <$> (mapM parseBlock $ elContent e)
996+ "footnote" -> (note . mconcat) <$>
997+ mapM parseBlock (elContent e)
994998 "title" -> return mempty
995999 "affiliation" -> return mempty
9961000 -- Note: this isn't a real docbook tag; it's what we convert
@@ -999,7 +1003,7 @@ parseInline (Elem e) =
9991003 "br" -> return linebreak
10001004 _ -> innerInlines
10011005 where innerInlines = (trimInlines . mconcat) <$>
1002− (mapM parseInline $ elContent e)
1006+ mapM parseInline (elContent e)
10031007 equation constructor = return $ mconcat $
10041008 map (constructor . writeTeX)
10051009 $ rights
src/Text/Pandoc/Readers/Docx/Combine.hs+12−12
@@ -36,16 +36,16 @@ spaceOutInlines ils =
3636 right = case viewr contents of
3737 (_ :> Space) -> space
3838 _ -> mempty in
39− (left, (stackInlines fs $ trimInlines . Many $ contents), right)
39+ (left, stackInlines fs $ trimInlines . Many $ contents, right)
4040
4141stackInlines :: [Modifier Inlines] -> Inlines -> Inlines
4242stackInlines [] ms = ms
4343stackInlines (NullModifier : fs) ms = stackInlines fs ms
44−stackInlines ((Modifier f) : fs) ms =
44+stackInlines (Modifier f : fs) ms =
4545 if isEmpty ms
4646 then stackInlines fs ms
4747 else f $ stackInlines fs ms
48−stackInlines ((AttrModifier f attr) : fs) ms = f attr $ stackInlines fs ms
48+stackInlines (AttrModifier f attr : fs) ms = f attr $ stackInlines fs ms
4949
5050unstackInlines :: Inlines -> ([Modifier Inlines], Inlines)
5151unstackInlines ms = case ilModifier ms of
@@ -97,7 +97,7 @@ combineInlines x y =
9797 let (xs', x') = inlinesR x
9898 (y', ys') = inlinesL y
9999 in
100− xs' <> (combineSingletonInlines x' y') <> ys'
100+ xs' <> combineSingletonInlines x' y' <> ys'
101101
102102combineSingletonInlines :: Inlines -> Inlines -> Inlines
103103combineSingletonInlines x y =
@@ -114,10 +114,10 @@ combineSingletonInlines x y =
114114 stackInlines (x_rem_attr ++ y_rem_attr) mempty
115115 | isEmpty xs ->
116116 let (sp, y') = spaceOutInlinesL y in
117− (stackInlines x_rem_attr mempty) <> sp <> y'
117+ stackInlines x_rem_attr mempty <> sp <> y'
118118 | isEmpty ys ->
119119 let (x', sp) = spaceOutInlinesR x in
120− x' <> sp <> (stackInlines y_rem_attr mempty)
120+ x' <> sp <> stackInlines y_rem_attr mempty
121121 | otherwise ->
122122 let (x', xsp) = spaceOutInlinesR x
123123 (ysp, y') = spaceOutInlinesL y
@@ -130,15 +130,15 @@ combineSingletonInlines x y =
130130
131131combineBlocks :: Blocks -> Blocks -> Blocks
132132combineBlocks bs cs
133− | bs' :> (BlockQuote bs'') <- viewr (unMany bs)
134− , (BlockQuote cs'') :< cs' <- viewl (unMany cs) =
135− Many $ (bs' |> (BlockQuote (bs'' <> cs''))) >< cs'
133+ | bs' :> BlockQuote bs'' <- viewr (unMany bs)
134+ , BlockQuote cs'' :< cs' <- viewl (unMany cs) =
135+ Many $ (bs' |> BlockQuote (bs'' <> cs'')) >< cs'
136136combineBlocks bs cs = bs <> cs
137137
138138instance (Monoid a, Eq a) => Eq (Modifier a) where
139− (Modifier f) == (Modifier g) = (f mempty == g mempty)
140− (AttrModifier f attr) == (AttrModifier g attr') = (f attr mempty == g attr' mempty)
141− (NullModifier) == (NullModifier) = True
139+ (Modifier f) == (Modifier g) = f mempty == g mempty
140+ (AttrModifier f attr) == (AttrModifier g attr') = f attr mempty == g attr' mempty
141+ NullModifier == NullModifier = True
142142 _ == _ = False
143143
144144isEmpty :: (Monoid a, Eq a) => a -> Bool
src/Text/Pandoc/Readers/Docx/Lists.hs+30−38
@@ -33,7 +33,6 @@ module Text.Pandoc.Readers.Docx.Lists ( blocksToBullets
3333 , listParagraphDivs
3434 ) where
3535
36−import Control.Monad
3736import Data.List
3837import Data.Maybe
3938import Text.Pandoc.Generic (bottomUp)
@@ -45,22 +44,18 @@ isListItem (Div (_, classes, _) _) | "list-item" `elem` classes = True
4544isListItem _ = False
4645
4746getLevel :: Block -> Maybe Integer
48−getLevel (Div (_, _, kvs) _) = liftM read $ lookup "level" kvs
47+getLevel (Div (_, _, kvs) _) = fmap read $ lookup "level" kvs
4948getLevel _ = Nothing
5049
5150getLevelN :: Block -> Integer
52−getLevelN b = case getLevel b of
53− Just n -> n
54− Nothing -> -1
51+getLevelN b = fromMaybe (-1) (getLevel b)
5552
5653getNumId :: Block -> Maybe Integer
57−getNumId (Div (_, _, kvs) _) = liftM read $ lookup "num-id" kvs
54+getNumId (Div (_, _, kvs) _) = fmap read $ lookup "num-id" kvs
5855getNumId _ = Nothing
5956
6057getNumIdN :: Block -> Integer
61−getNumIdN b = case getNumId b of
62− Just n -> n
63− Nothing -> -1
58+getNumIdN b = fromMaybe (-1) (getNumId b)
6459
6560getText :: Block -> Maybe String
6661getText (Div (_, _, kvs) _) = lookup "text" kvs
@@ -109,27 +104,27 @@ listParagraphDivs = ["ListParagraph"]
109104handleListParagraphs :: [Block] -> [Block]
110105handleListParagraphs [] = []
111106handleListParagraphs (
112− (Div attr1@(_, classes1, _) blks1) :
113− (Div (ident2, classes2, kvs2) blks2) :
107+ Div attr1@(_, classes1, _) blks1 :
108+ Div (ident2, classes2, kvs2) blks2 :
114109 blks
115110 ) | "list-item" `elem` classes1 &&
116− not ("list-item" `elem` classes2) &&
111+ notElem "list-item" classes2 &&
117112 (not . null) (listParagraphDivs `intersect` classes2) =
118113 -- We don't want to keep this indent.
119114 let newDiv2 =
120− (Div (ident2, classes2, filter (\kv -> fst kv /= "indent") kvs2) blks2)
115+ Div (ident2, classes2, filter (\kv -> fst kv /= "indent") kvs2) blks2
121116 in
122− handleListParagraphs ((Div attr1 (blks1 ++ [newDiv2])) : blks)
123−handleListParagraphs (blk:blks) = blk : (handleListParagraphs blks)
117+ handleListParagraphs (Div attr1 (blks1 ++ [newDiv2]) : blks)
118+handleListParagraphs (blk:blks) = blk : handleListParagraphs blks
124119
125120separateBlocks' :: Block -> [[Block]] -> [[Block]]
126−separateBlocks' blk ([] : []) = [[blk]]
127−separateBlocks' b@(BulletList _) acc = (init acc) ++ [(last acc) ++ [b]]
128−separateBlocks' b@(OrderedList _ _) acc = (init acc) ++ [(last acc) ++ [b]]
121+separateBlocks' blk [[]] = [[blk]]
122+separateBlocks' b@(BulletList _) acc = init acc ++ [last acc ++ [b]]
123+separateBlocks' b@(OrderedList _ _) acc = init acc ++ [last acc ++ [b]]
129124-- The following is for the invisible bullet lists. This is how
130125-- pandoc-generated ooxml does multiparagraph item lists.
131−separateBlocks' b acc | liftM trim (getText b) == Just "" =
132− (init acc) ++ [(last acc) ++ [b]]
126+separateBlocks' b acc | fmap trim (getText b) == Just "" =
127+ init acc ++ [last acc ++ [b]]
133128separateBlocks' b acc = acc ++ [[b]]
134129
135130separateBlocks :: [Block] -> [[Block]]
@@ -138,38 +133,37 @@ separateBlocks blks = foldr separateBlocks' [[]] (reverse blks)
138133flatToBullets' :: Integer -> [Block] -> [Block]
139134flatToBullets' _ [] = []
140135flatToBullets' num xs@(b : elems)
141− | getLevelN b == num = b : (flatToBullets' num elems)
136+ | getLevelN b == num = b : flatToBullets' num elems
142137 | otherwise =
143138 let bNumId = getNumIdN b
144139 bLevel = getLevelN b
145140 (children, remaining) =
146141 span
147142 (\b' ->
148− ((getLevelN b') > bLevel ||
149− ((getLevelN b') == bLevel && (getNumIdN b') == bNumId)))
143+ (getLevelN b') > bLevel ||
144+ ((getLevelN b') == bLevel && (getNumIdN b') == bNumId))
150145 xs
151146 in
152147 case getListType b of
153148 Just (Enumerated attr) ->
154− (OrderedList attr (separateBlocks $ flatToBullets' bLevel children)) :
155− (flatToBullets' num remaining)
149+ OrderedList attr (separateBlocks $ flatToBullets' bLevel children) :
150+ flatToBullets' num remaining
156151 _ ->
157− (BulletList (separateBlocks $ flatToBullets' bLevel children)) :
158− (flatToBullets' num remaining)
152+ BulletList (separateBlocks $ flatToBullets' bLevel children) :
153+ flatToBullets' num remaining
159154
160155flatToBullets :: [Block] -> [Block]
161156flatToBullets elems = flatToBullets' (-1) elems
162157
163158singleItemHeaderToHeader :: Block -> Block
164−singleItemHeaderToHeader (OrderedList _ [[h@(Header _ _ _)]]) = h
159+singleItemHeaderToHeader (OrderedList _ [[h@(Header{})]]) = h
165160singleItemHeaderToHeader blk = blk
166161
167162
168163blocksToBullets :: [Block] -> [Block]
169164blocksToBullets blks =
170165 map singleItemHeaderToHeader $
171− bottomUp removeListDivs $
172− flatToBullets $ (handleListParagraphs blks)
166+ bottomUp removeListDivs $flatToBullets (handleListParagraphs blks)
173167
174168plainParaInlines :: Block -> [Inline]
175169plainParaInlines (Plain ils) = ils
@@ -179,18 +173,16 @@ plainParaInlines _ = []
179173blocksToDefinitions' :: [([Inline], [[Block]])] -> [Block] -> [Block] -> [Block]
180174blocksToDefinitions' [] acc [] = reverse acc
181175blocksToDefinitions' defAcc acc [] =
182− reverse $ (DefinitionList (reverse defAcc)) : acc
176+ reverse $ DefinitionList (reverse defAcc) : acc
183177blocksToDefinitions' defAcc acc
184− ((Div (_, classes1, _) blks1) : (Div (ident2, classes2, kvs2) blks2) : blks)
178+ (Div (_, classes1, _) blks1 : Div (ident2, classes2, kvs2) blks2 : blks)
185179 | "DefinitionTerm" `elem` classes1 && "Definition" `elem` classes2 =
186180 let remainingAttr2 = (ident2, delete "Definition" classes2, kvs2)
187− pair = case remainingAttr2 == ("", [], []) of
188− True -> (concatMap plainParaInlines blks1, [blks2])
189− False -> (concatMap plainParaInlines blks1, [[Div remainingAttr2 blks2]])
181+ pair = if remainingAttr2 == ("", [], []) then (concatMap plainParaInlines blks1, [blks2]) else (concatMap plainParaInlines blks1, [[Div remainingAttr2 blks2]])
190182 in
191183 blocksToDefinitions' (pair : defAcc) acc blks
192184blocksToDefinitions' defAcc acc
193− ((Div (ident2, classes2, kvs2) blks2) : blks)
185+ (Div (ident2, classes2, kvs2) blks2 : blks)
194186 | (not . null) defAcc && "Definition" `elem` classes2 =
195187 let remainingAttr2 = (ident2, delete "Definition" classes2, kvs2)
196188 defItems2 = case remainingAttr2 == ("", [], []) of
@@ -205,14 +197,14 @@ blocksToDefinitions' defAcc acc
205197blocksToDefinitions' [] acc (b:blks) =
206198 blocksToDefinitions' [] (b:acc) blks
207199blocksToDefinitions' defAcc acc (b:blks) =
208− blocksToDefinitions' [] (b : (DefinitionList (reverse defAcc)) : acc) blks
200+ blocksToDefinitions' [] (b : DefinitionList (reverse defAcc) : acc) blks
209201
210202removeListDivs' :: Block -> [Block]
211203removeListDivs' (Div (ident, classes, kvs) blks)
212204 | "list-item" `elem` classes =
213205 case delete "list-item" classes of
214206 [] -> blks
215− classes' -> [Div (ident, classes', kvs) $ blks]
207+ classes' -> [Div (ident, classes', kvs) blks]
216208removeListDivs' (Div (ident, classes, kvs) blks)
217209 | not $ null $ listParagraphDivs `intersect` classes =
218210 case classes \\ listParagraphDivs of
src/Text/Pandoc/Readers/Docx/Parse.hs+13−13
@@ -106,7 +106,7 @@ eitherToD (Right b) = return b
106106eitherToD (Left _) = throwError DocxError
107107
108108concatMapM :: (Monad m) => (a -> m [b]) -> [a] -> m [b]
109−concatMapM f xs = liftM concat (mapM f xs)
109+concatMapM f xs = fmap concat (mapM f xs)
110110
111111
112112-- This is similar to `mapMaybe`: it maps a function returning the D
@@ -304,7 +304,7 @@ archiveToDocument zf = do
304304elemToBody :: NameSpaces -> Element -> D Body
305305elemToBody ns element | isElem ns "w" "body" element =
306306 mapD (elemToBodyPart ns) (elChildren element) >>=
307− (\bps -> return $ Body bps)
307+ (return . Body)
308308elemToBody _ _ = throwError WrongElem
309309
310310archiveToStyles :: Archive -> (CharStyleMap, ParStyleMap)
@@ -329,7 +329,7 @@ isBasedOnStyle ns element parentStyle
329329 , styleType == cStyleType parentStyle
330330 , Just basedOnVal <- findChildByName ns "w" "basedOn" element >>=
331331 findAttrByName ns "w" "val"
332− , Just ps <- parentStyle = (basedOnVal == getStyleId ps)
332+ , Just ps <- parentStyle = basedOnVal == getStyleId ps
333333 | isElem ns "w" "style" element
334334 , Just styleType <- findAttrByName ns "w" "type" element
335335 , styleType == cStyleType parentStyle
@@ -371,10 +371,10 @@ getStyleChildren ns element parentStyle
371371
372372buildBasedOnList :: (ElemToStyle a) => NameSpaces -> Element -> Maybe a -> [a]
373373buildBasedOnList ns element rootStyle =
374− case (getStyleChildren ns element rootStyle) of
374+ case getStyleChildren ns element rootStyle of
375375 [] -> []
376376 stys -> stys ++
377− (concatMap (\s -> buildBasedOnList ns element (Just s)) stys)
377+ concatMap (\s -> buildBasedOnList ns element (Just s)) stys
378378
379379archiveToNotes :: Archive -> Notes
380380archiveToNotes zf =
@@ -389,8 +389,8 @@ archiveToNotes zf =
389389 Just e -> elemToNameSpaces e
390390 Nothing -> []
391391 ns = unionBy (\x y -> fst x == fst y) fn_namespaces en_namespaces
392− fn = fnElem >>= (elemToNotes ns "footnote")
393− en = enElem >>= (elemToNotes ns "endnote")
392+ fn = fnElem >>= elemToNotes ns "footnote"
393+ en = enElem >>= elemToNotes ns "endnote"
394394 in
395395 Notes ns fn en
396396
@@ -401,7 +401,7 @@ archiveToComments zf =
401401 cmts_namespaces = case cmtsElem of
402402 Just e -> elemToNameSpaces e
403403 Nothing -> []
404− cmts = (elemToComments cmts_namespaces) <$> cmtsElem
404+ cmts = elemToComments cmts_namespaces <$> cmtsElem
405405 in
406406 case cmts of
407407 Just c -> Comments cmts_namespaces c
@@ -442,8 +442,7 @@ lookupLevel :: String -> String -> Numbering -> Maybe Level
442442lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
443443 absNumId <- lookup numId $ map (\(Numb nid absnumid) -> (nid, absnumid)) numbs
444444 lvls <- lookup absNumId $ map (\(AbstractNumb aid ls) -> (aid, ls)) absNumbs
445− lvl <- lookup ilvl $ map (\l@(i, _, _, _) -> (i, l)) lvls
446− return lvl
445+ lookup ilvl $ map (\l@(i, _, _, _) -> (i, l)) lvls
447446
448447
449448numElemToNum :: NameSpaces -> Element -> Maybe Numb
@@ -479,7 +478,7 @@ levelElemToLevel ns element
479478levelElemToLevel _ _ = Nothing
480479
481480archiveToNumbering' :: Archive -> Maybe Numbering
482−archiveToNumbering' zf = do
481+archiveToNumbering' zf =
483482 case findEntryByPath "word/numbering.xml" zf of
484483 Nothing -> Just $ Numbering [] [] []
485484 Just entry -> do
@@ -503,7 +502,8 @@ elemToNotes ns notetype element
503502 (\a -> Just (a, e)))
504503 (findChildrenByName ns "w" notetype element)
505504 in
506− Just $ M.fromList $ pairs
505+ Just $
506+ M.fromList pairs
507507elemToNotes _ _ _ = Nothing
508508
509509elemToComments :: NameSpaces -> Element -> M.Map String Element
@@ -514,7 +514,7 @@ elemToComments ns element
514514 (\a -> Just (a, e)))
515515 (findChildrenByName ns "w" "comment" element)
516516 in
517− M.fromList $ pairs
517+ M.fromList pairs
518518elemToComments _ _ = M.empty
519519
520520