git.iko.soy/typeable/pandoc
on master help sign in
hlint suggestions.
commitcbcb9b36c088b3dd1e07f9d0318594b78e5d38f2 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 27 Oct 2017, 23:13 (9 years ago) parent8481298
33 files changed+307−340
pandoc.hs−1 src/Text/Pandoc/CSV.hs−1 src/Text/Pandoc/Class.hs−1 src/Text/Pandoc/Emoji.hs−1 src/Text/Pandoc/ImageSize.hs−1 src/Text/Pandoc/Lua/StackInstances.hs+10−10 src/Text/Pandoc/MIME.hs−1 src/Text/Pandoc/PDF.hs−1 src/Text/Pandoc/Readers/Creole.hs+1−1 src/Text/Pandoc/Readers/Docx.hs+37−38 src/Text/Pandoc/Readers/Docx/Lists.hs+1−1 src/Text/Pandoc/Readers/Docx/Parse.hs+10−16 src/Text/Pandoc/Readers/Docx/Util.hs−1 src/Text/Pandoc/Readers/EPUB.hs+11−11 src/Text/Pandoc/Readers/Haddock.hs+1−1 src/Text/Pandoc/Readers/LaTeX.hs+34−34 src/Text/Pandoc/Readers/LaTeX/Types.hs−1 src/Text/Pandoc/Readers/Markdown.hs+33−37 src/Text/Pandoc/Readers/Muse.hs+9−9 src/Text/Pandoc/Readers/Native.hs−1 src/Text/Pandoc/Readers/OPML.hs+7−8 src/Text/Pandoc/Readers/Odt/Arrows/State.hs+3−3 src/Text/Pandoc/Readers/Odt/Base.hs+1−2 src/Text/Pandoc/Readers/Odt/Generic/Fallible.hs+2−2 src/Text/Pandoc/Readers/Odt/Generic/Utils.hs+2−2 src/Text/Pandoc/Readers/Textile.hs+1−1 src/Text/Pandoc/Readers/TikiWiki.hs+50−54 src/Text/Pandoc/Readers/Vimwiki.hs+64−65 src/Text/Pandoc/SelfContained.hs+5−8 src/Text/Pandoc/Shared.hs+21−22 src/Text/Pandoc/Slides.hs+2−2 src/Text/Pandoc/Templates.hs+2−2 src/Text/Pandoc/UUID.hs−1
pandoc.hs−1
@@ -36,4 +36,3 @@ import Text.Pandoc.Error (handleError)
3636main :: IO ()
3737main = E.catch (parseOptions options defaultOpts >>= convertWithOpts)
3838 (handleError . Left)
39−
src/Text/Pandoc/CSV.hs−1
@@ -100,4 +100,3 @@ endline :: Parser ()
100100endline = do
101101 optional (void $ char '\r')
102102 void $ char '\n'
103−
src/Text/Pandoc/Class.hs−1
@@ -997,4 +997,3 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
997997 else "")
998998 (return ())
999999 logOutput = lift . logOutput
1000−
src/Text/Pandoc/Emoji.hs−1
@@ -903,4 +903,3 @@ emojis = M.fromList
903903 ,("zero","0\65039\8419")
904904 ,("zzz","\128164")
905905 ]
906−
src/Text/Pandoc/ImageSize.hs−1
@@ -602,4 +602,3 @@ tagTypeTable = M.fromList
602602 , (0xa300, FileSource)
603603 , (0xa301, SceneType)
604604 ]
605−
src/Text/Pandoc/Lua/StackInstances.hs+10−10
@@ -208,18 +208,18 @@ peekBlock idx = do
208208 case tag of
209209 "BlockQuote" -> BlockQuote <$> elementContent
210210 "BulletList" -> BulletList <$> elementContent
211− "CodeBlock" -> (withAttr CodeBlock) <$> elementContent
211+ "CodeBlock" -> withAttr CodeBlock <$> elementContent
212212 "DefinitionList" -> DefinitionList <$> elementContent
213− "Div" -> (withAttr Div) <$> elementContent
213+ "Div" -> withAttr Div <$> elementContent
214214 "Header" -> (\(lvl, LuaAttr attr, lst) -> Header lvl attr lst)
215215 <$> elementContent
216216 "HorizontalRule" -> return HorizontalRule
217217 "LineBlock" -> LineBlock <$> elementContent
218− "OrderedList" -> (uncurry OrderedList) <$> elementContent
218+ "OrderedList" -> uncurry OrderedList <$> elementContent
219219 "Null" -> return Null
220220 "Para" -> Para <$> elementContent
221221 "Plain" -> Plain <$> elementContent
222− "RawBlock" -> (uncurry RawBlock) <$> elementContent
222+ "RawBlock" -> uncurry RawBlock <$> elementContent
223223 "Table" -> (\(capt, aligns, widths, headers, body) ->
224224 Table capt aligns widths headers body)
225225 <$> elementContent
@@ -257,8 +257,8 @@ peekInline :: StackIndex -> Lua Inline
257257peekInline idx = do
258258 tag <- getTag idx
259259 case tag of
260− "Cite" -> (uncurry Cite) <$> elementContent
261− "Code" -> (withAttr Code) <$> elementContent
260+ "Cite" -> uncurry Cite <$> elementContent
261+ "Code" -> withAttr Code <$> elementContent
262262 "Emph" -> Emph <$> elementContent
263263 "Image" -> (\(LuaAttr attr, lst, tgt) -> Image attr lst tgt)
264264 <$> elementContent
@@ -266,13 +266,13 @@ peekInline idx = do
266266 <$> elementContent
267267 "LineBreak" -> return LineBreak
268268 "Note" -> Note <$> elementContent
269− "Math" -> (uncurry Math) <$> elementContent
270− "Quoted" -> (uncurry Quoted) <$> elementContent
271− "RawInline" -> (uncurry RawInline) <$> elementContent
269+ "Math" -> uncurry Math <$> elementContent
270+ "Quoted" -> uncurry Quoted <$> elementContent
271+ "RawInline" -> uncurry RawInline <$> elementContent
272272 "SmallCaps" -> SmallCaps <$> elementContent
273273 "SoftBreak" -> return SoftBreak
274274 "Space" -> return Space
275− "Span" -> (withAttr Span) <$> elementContent
275+ "Span" -> withAttr Span <$> elementContent
276276 "Str" -> Str <$> elementContent
277277 "Strikeout" -> Strikeout <$> elementContent
278278 "Strong" -> Strong <$> elementContent
src/Text/Pandoc/MIME.hs−1
@@ -525,4 +525,3 @@ mimeTypesList = -- List borrowed from happstack-server.
525525 ,("zip","application/zip")
526526 ,("zmt","chemical/x-mopac-input")
527527 ]
528−
src/Text/Pandoc/PDF.hs−1
@@ -438,4 +438,3 @@ context2pdf verbosity tmpDir source = inDirectory tmpDir $ do
438438 return $ Left logmsg
439439 (ExitSuccess, Nothing) -> return $ Left ""
440440 (ExitSuccess, Just pdf) -> return $ Right pdf
441−
src/Text/Pandoc/Readers/Creole.hs+1−1
@@ -282,7 +282,7 @@ placeholder = B.text <$> try (string "<<<" >> manyTill anyChar (string ">>>")
282282 >> return "")
283283
284284whitespace :: PandocMonad m => CRLParser m B.Inlines
285−whitespace = (lb <|> regsp)
285+whitespace = lb <|> regsp
286286 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
287287 regsp = try $ skipMany1 spaceChar >> return B.space
288288
src/Text/Pandoc/Readers/Docx.hs+37−38
@@ -139,7 +139,7 @@ instance Default DEnv where
139139type DocxContext m = ReaderT DEnv (StateT DState m)
140140
141141evalDocxContext :: PandocMonad m => DocxContext m a -> DEnv -> DState -> m a
142−evalDocxContext ctx env st = flip evalStateT st $ flip runReaderT env $ ctx
142+evalDocxContext ctx env st = flip evalStateT st $flip runReaderT env ctx
143143
144144-- This is empty, but we put it in for future-proofing.
145145spansToKeep :: [String]
@@ -156,7 +156,7 @@ metaStyles = M.fromList [ ("Title", "title")
156156 , ("Abstract", "abstract")]
157157
158158sepBodyParts :: [BodyPart] -> ([BodyPart], [BodyPart])
159−sepBodyParts = span (\bp -> (isMetaPar bp || isEmptyPar bp))
159+sepBodyParts = span (\bp -> isMetaPar bp || isEmptyPar bp)
160160
161161isMetaPar :: BodyPart -> Bool
162162isMetaPar (Paragraph pPr _) =
@@ -183,7 +183,7 @@ bodyPartsToMeta' (bp : bps)
183183 remaining <- bodyPartsToMeta' bps
184184 let
185185 f (MetaInlines ils) (MetaInlines ils') = MetaBlocks [Para ils, Para ils']
186− f (MetaInlines ils) (MetaBlocks blks) = MetaBlocks ((Para ils) : blks)
186+ f (MetaInlines ils) (MetaBlocks blks) = MetaBlocks (Para ils : blks)
187187 f m (MetaList mv) = MetaList (m : mv)
188188 f m n = MetaList [m, n]
189189 return $ M.insertWith f metaField (MetaInlines (toList inlines)) remaining
@@ -215,17 +215,17 @@ codeDivs = ["SourceCode"]
215215
216216runElemToInlines :: RunElem -> Inlines
217217runElemToInlines (TextRun s) = text s
218−runElemToInlines (LnBrk) = linebreak
219−runElemToInlines (Tab) = space
220−runElemToInlines (SoftHyphen) = text "\xad"
221−runElemToInlines (NoBreakHyphen) = text "\x2011"
218+runElemToInlines LnBrk = linebreak
219+runElemToInlines Tab = space
220+runElemToInlines SoftHyphen = text "\xad"
221+runElemToInlines NoBreakHyphen = text "\x2011"
222222
223223runElemToString :: RunElem -> String
224224runElemToString (TextRun s) = s
225−runElemToString (LnBrk) = ['\n']
226−runElemToString (Tab) = ['\t']
227−runElemToString (SoftHyphen) = ['\xad']
228−runElemToString (NoBreakHyphen) = ['\x2011']
225+runElemToString LnBrk = ['\n']
226+runElemToString Tab = ['\t']
227+runElemToString SoftHyphen = ['\xad']
228+runElemToString NoBreakHyphen = ['\x2011']
229229
230230runToString :: Run -> String
231231runToString (Run _ runElems) = concatMap runElemToString runElems
@@ -274,21 +274,21 @@ runStyleToTransform rPr
274274 , s `elem` spansToKeep =
275275 let rPr' = rPr{rStyle = Nothing}
276276 in
277− (spanWith ("", [s], [])) . (runStyleToTransform rPr')
277+ spanWith ("", [s], []) . runStyleToTransform rPr'
278278 | Just True <- isItalic rPr =
279− emph . (runStyleToTransform rPr {isItalic = Nothing})
279+ emph . runStyleToTransform rPr {isItalic = Nothing}
280280 | Just True <- isBold rPr =
281− strong . (runStyleToTransform rPr {isBold = Nothing})
281+ strong . runStyleToTransform rPr {isBold = Nothing}
282282 | Just True <- isSmallCaps rPr =
283− smallcaps . (runStyleToTransform rPr {isSmallCaps = Nothing})
283+ smallcaps . runStyleToTransform rPr {isSmallCaps = Nothing}
284284 | Just True <- isStrike rPr =
285− strikeout . (runStyleToTransform rPr {isStrike = Nothing})
285+ strikeout . runStyleToTransform rPr {isStrike = Nothing}
286286 | Just SupScrpt <- rVertAlign rPr =
287− superscript . (runStyleToTransform rPr {rVertAlign = Nothing})
287+ superscript . runStyleToTransform rPr {rVertAlign = Nothing}
288288 | Just SubScrpt <- rVertAlign rPr =
289− subscript . (runStyleToTransform rPr {rVertAlign = Nothing})
289+ subscript . runStyleToTransform rPr {rVertAlign = Nothing}
290290 | Just "single" <- rUnderline rPr =
291− underlineSpan . (runStyleToTransform rPr {rUnderline = Nothing})
291+ underlineSpan . runStyleToTransform rPr {rUnderline = Nothing}
292292 | otherwise = id
293293
294294runToInlines :: PandocMonad m => Run -> DocxContext m Inlines
@@ -306,10 +306,10 @@ runToInlines (Run rs runElems)
306306 let ils = smushInlines (map runElemToInlines runElems)
307307 return $ (runStyleToTransform $ resolveDependentRunStyle rs) ils
308308runToInlines (Footnote bps) = do
309− blksList <- smushBlocks <$> (mapM bodyPartToBlocks bps)
309+ blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
310310 return $ note blksList
311311runToInlines (Endnote bps) = do
312− blksList <- smushBlocks <$> (mapM bodyPartToBlocks bps)
312+ blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
313313 return $ note blksList
314314runToInlines (InlineDrawing fp title alt bs ext) = do
315315 (lift . lift) $ P.insertMedia fp Nothing bs
@@ -330,7 +330,7 @@ blocksToInlinesWarn cmtId blks = do
330330 notParaOrPlain (Para _) = False
331331 notParaOrPlain (Plain _) = False
332332 notParaOrPlain _ = True
333− when (not $ null $ filter notParaOrPlain blkList) $
333+ unless (null $ filter notParaOrPlain blkList) $
334334 lift $ P.report $ DocxParserWarning $
335335 "Docx comment " ++ cmtId ++ " will not retain formatting"
336336 return $ fromList $ blocksToInlines blkList
@@ -390,7 +390,7 @@ parPartToInlines (BookMark _ anchor) =
390390 -- are not defined in pandoc, it seems like a necessary evil to
391391 -- avoid an extra pass.
392392 let newAnchor =
393− if not inHdrBool && anchor `elem` (M.elems anchorMap)
393+ if not inHdrBool && anchor `elem` M.elems anchorMap
394394 then uniqueIdent [Str anchor] (Set.fromList $ M.elems anchorMap)
395395 else anchor
396396 unless inHdrBool
@@ -399,7 +399,7 @@ parPartToInlines (BookMark _ anchor) =
399399parPartToInlines (Drawing fp title alt bs ext) = do
400400 (lift . lift) $ P.insertMedia fp Nothing bs
401401 return $ imageWith (extentToAttr ext) fp title $ text alt
402−parPartToInlines Chart = do
402+parPartToInlines Chart =
403403 return $ spanWith ("", ["chart"], []) $ text "[CHART]"
404404parPartToInlines (InternalHyperLink anchor runs) = do
405405 ils <- smushInlines <$> mapM runToInlines runs
@@ -407,11 +407,10 @@ parPartToInlines (InternalHyperLink anchor runs) = do
407407parPartToInlines (ExternalHyperLink target runs) = do
408408 ils <- smushInlines <$> mapM runToInlines runs
409409 return $ link target "" ils
410−parPartToInlines (PlainOMath exps) = do
410+parPartToInlines (PlainOMath exps) =
411411 return $ math $ writeTeX exps
412412parPartToInlines (SmartTag runs) = do
413− ils <- smushInlines <$> mapM runToInlines runs
414− return ils
413+ smushInlines <$> mapM runToInlines runs
415414
416415isAnchorSpan :: Inline -> Bool
417416isAnchorSpan (Span (_, classes, kvs) _) =
@@ -454,7 +453,7 @@ makeHeaderAnchor' blk = return blk
454453-- Rewrite a standalone paragraph block as a plain
455454singleParaToPlain :: Blocks -> Blocks
456455singleParaToPlain blks
457− | (Para (ils) :< seeq) <- viewl $ unMany blks
456+ | (Para ils :< seeq) <- viewl $ unMany blks
458457 , Seq.null seeq =
459458 singleton $ Plain ils
460459singleParaToPlain blks = blks
@@ -471,7 +470,7 @@ rowToBlocksList (Row cells) = do
471470
472471-- like trimInlines, but also take out linebreaks
473472trimSps :: Inlines -> Inlines
474−trimSps (Many ils) = Many $ Seq.dropWhileL isSp $ Seq.dropWhileR isSp $ ils
473+trimSps (Many ils) = Many $ Seq.dropWhileL isSp $Seq.dropWhileR isSp ils
475474 where isSp Space = True
476475 isSp SoftBreak = True
477476 isSp LineBreak = True
@@ -483,17 +482,17 @@ parStyleToTransform pPr
483482 , c `elem` divsToKeep =
484483 let pPr' = pPr { pStyle = cs }
485484 in
486− (divWith ("", [c], [])) . (parStyleToTransform pPr')
485+ divWith ("", [c], []) . parStyleToTransform pPr'
487486 | (c:cs) <- pStyle pPr,
488487 c `elem` listParagraphDivs =
489488 let pPr' = pPr { pStyle = cs, indentation = Nothing}
490489 in
491− (divWith ("", [c], [])) . (parStyleToTransform pPr')
490+ divWith ("", [c], []) . parStyleToTransform pPr'
492491 | (_:cs) <- pStyle pPr
493492 , Just True <- pBlockQuote pPr =
494493 let pPr' = pPr { pStyle = cs }
495494 in
496− blockQuote . (parStyleToTransform pPr')
495+ blockQuote . parStyleToTransform pPr'
497496 | (_:cs) <- pStyle pPr =
498497 let pPr' = pPr { pStyle = cs}
499498 in
@@ -523,7 +522,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
523522 $ codeBlock
524523 $ concatMap parPartToString parparts
525524 | Just (style, n) <- pHeading pPr = do
526− ils <- local (\s-> s{docxInHeaderBlock=True}) $
525+ ils <-local (\s-> s{docxInHeaderBlock=True})
527526 (smushInlines <$> mapM parPartToInlines parparts)
528527 makeHeaderAnchor $
529528 headerWith ("", delete style (pStyle pPr), []) n ils
@@ -545,7 +544,7 @@ bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
545544 , ("num-id", numId)
546545 , ("format", fmt)
547546 , ("text", txt)
548− , ("start", (show start))
547+ , ("start", show start)
549548 ]
550549
551550 (_, fmt, txt, Nothing) -> [ ("level", lvl)
@@ -556,7 +555,7 @@ bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
556555 blks <- bodyPartToBlocks (Paragraph pPr parparts)
557556 return $ divWith ("", ["list-item"], kvs) blks
558557bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
559− let pPr' = pPr {pStyle = "ListParagraph": (pStyle pPr)}
558+ let pPr' = pPr {pStyle = "ListParagraph": pStyle pPr}
560559 in
561560 bodyPartToBlocks $ Paragraph pPr' parparts
562561bodyPartToBlocks (Tbl _ _ _ []) =
@@ -588,7 +587,7 @@ bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
588587 widths = replicate width 0 :: [Double]
589588
590589 return $ table caption (zip alignments widths) hdrCells cells
591−bodyPartToBlocks (OMathPara e) = do
590+bodyPartToBlocks (OMathPara e) =
592591 return $ para $ displayMath (writeTeX e)
593592
594593
@@ -597,7 +596,7 @@ rewriteLink' :: PandocMonad m => Inline -> DocxContext m Inline
597596rewriteLink' l@(Link attr ils ('#':target, title)) = do
598597 anchorMap <- gets docxAnchorMap
599598 return $ case M.lookup target anchorMap of
600− Just newTarget -> (Link attr ils ('#':newTarget, title))
599+ Just newTarget -> Link attr ils ('#':newTarget, title)
601600 Nothing -> l
602601rewriteLink' il = return il
603602
@@ -610,7 +609,7 @@ bodyToOutput (Body bps) = do
610609 meta <- bodyPartsToMeta metabps
611610 blks <- smushBlocks <$> mapM bodyPartToBlocks blkbps
612611 blks' <- rewriteLinks $ blocksToDefinitions $ blocksToBullets $ toList blks
613− return $ (meta, blks')
612+ return (meta, blks')
614613
615614docxToOutput :: PandocMonad m
616615 => ReaderOptions
src/Text/Pandoc/Readers/Docx/Lists.hs+1−1
@@ -156,7 +156,7 @@ flatToBullets :: [Block] -> [Block]
156156flatToBullets elems = flatToBullets' (-1) elems
157157
158158singleItemHeaderToHeader :: Block -> Block
159−singleItemHeaderToHeader (OrderedList _ [[h@(Header{})]]) = h
159+singleItemHeaderToHeader (OrderedList _ [[h@Header{}]]) = h
160160singleItemHeaderToHeader blk = blk
161161
162162
src/Text/Pandoc/Readers/Docx/Parse.hs+10−16
@@ -303,8 +303,7 @@ archiveToDocument zf = do
303303
304304elemToBody :: NameSpaces -> Element -> D Body
305305elemToBody ns element | isElem ns "w" "body" element =
306− mapD (elemToBodyPart ns) (elChildren element) >>=
307− (return . Body)
306+ fmap Body (mapD (elemToBodyPart ns) (elChildren element))
308307elemToBody _ _ = throwError WrongElem
309308
310309archiveToStyles :: Archive -> (CharStyleMap, ParStyleMap)
@@ -374,7 +373,7 @@ buildBasedOnList ns element rootStyle =
374373 case getStyleChildren ns element rootStyle of
375374 [] -> []
376375 stys -> stys ++
377− concatMap (\s -> buildBasedOnList ns element (Just s)) stys
376+ concatMap (buildBasedOnList ns element . Just) stys
378377
379378archiveToNotes :: Archive -> Notes
380379archiveToNotes zf =
@@ -577,7 +576,7 @@ testBitMask :: String -> Int -> Bool
577576testBitMask bitMaskS n =
578577 case (reads ("0x" ++ bitMaskS) :: [(Int, String)]) of
579578 [] -> False
580− ((n', _) : _) -> ((n' .|. n) /= 0)
579+ ((n', _) : _) -> (n' .|. n) /= 0
581580
582581stringToInteger :: String -> Maybe Integer
583582stringToInteger s = listToMaybe $ map fst (reads s :: [(Integer, String)])
@@ -654,12 +653,8 @@ getTitleAndAlt :: NameSpaces -> Element -> (String, String)
654653getTitleAndAlt ns element =
655654 let mbDocPr = findChildByName ns "wp" "inline" element >>=
656655 findChildByName ns "wp" "docPr"
657− title = case mbDocPr >>= findAttrByName ns "" "title" of
658− Just title' -> title'
659− Nothing -> ""
660− alt = case mbDocPr >>= findAttrByName ns "" "descr" of
661− Just alt' -> alt'
662− Nothing -> ""
656+ title = fromMaybe "" (mbDocPr >>= findAttrByName ns "" "title")
657+ alt = fromMaybe "" (mbDocPr >>= findAttrByName ns "" "descr")
663658 in (title, alt)
664659
665660elemToParPart :: NameSpaces -> Element -> D ParPart
@@ -727,7 +722,7 @@ elemToParPart ns element
727722 runs <- mapD (elemToRun ns) (elChildren element)
728723 rels <- asks envRelationships
729724 case lookupRelationship location relId rels of
730− Just target -> do
725+ Just target ->
731726 case findAttrByName ns "w" "anchor" element of
732727 Just anchor -> return $ ExternalHyperLink (target ++ '#':anchor) runs
733728 Nothing -> return $ ExternalHyperLink target runs
@@ -750,7 +745,7 @@ elemToParPart ns element
750745 return $ CommentEnd cmtId
751746elemToParPart ns element
752747 | isElem ns "m" "oMath" element =
753− (eitherToD $ readOMML $ showElement element) >>= (return . PlainOMath)
748+ fmap PlainOMath (eitherToD $ readOMML $ showElement element)
754749elemToParPart _ _ = throwError WrongElem
755750
756751elemToCommentStart :: NameSpaces -> Element -> D ParPart
@@ -764,10 +759,10 @@ elemToCommentStart ns element
764759elemToCommentStart _ _ = throwError WrongElem
765760
766761lookupFootnote :: String -> Notes -> Maybe Element
767−lookupFootnote s (Notes _ fns _) = fns >>= (M.lookup s)
762+lookupFootnote s (Notes _ fns _) = fns >>= M.lookup s
768763
769764lookupEndnote :: String -> Notes -> Maybe Element
770−lookupEndnote s (Notes _ _ ens) = ens >>= (M.lookup s)
765+lookupEndnote s (Notes _ _ ens) = ens >>= M.lookup s
771766
772767elemToExtent :: Element -> Extent
773768elemToExtent drawingElem =
@@ -1035,11 +1030,10 @@ elemToRunElems ns element
10351030 let font = do
10361031 fontElem <- findElement (qualName "rFonts") element
10371032 stringToFont =<<
1038− (foldr (<|>) Nothing $
1033+ foldr (<|>) Nothing (
10391034 map (flip findAttr fontElem . qualName) ["ascii", "hAnsi"])
10401035 local (setFont font) (mapD (elemToRunElem ns) (elChildren element))
10411036elemToRunElems _ _ = throwError WrongElem
10421037
10431038setFont :: Maybe Font -> ReaderEnv -> ReaderEnv
10441039setFont f s = s{envFont = f}
1045−
src/Text/Pandoc/Readers/Docx/Util.hs−1
@@ -44,4 +44,3 @@ findAttrByName :: NameSpaces -> String -> String -> Element -> Maybe String
4444findAttrByName ns pref name el =
4545 let ns' = ns ++ elemToNameSpaces el
4646 in findAttr (elemName ns' pref name) el
47−
src/Text/Pandoc/Readers/EPUB.hs+11−11
@@ -1,5 +1,5 @@
11{-# LANGUAGE FlexibleContexts #-}
2−{-# LANGUAGE StandaloneDeriving #-}
2+
33{-# LANGUAGE TupleSections #-}
44{-# LANGUAGE ViewPatterns #-}
55
@@ -39,7 +39,7 @@ type Items = M.Map String (FilePath, MimeType)
3939
4040readEPUB :: PandocMonad m => ReaderOptions -> BL.ByteString -> m Pandoc
4141readEPUB opts bytes = case toArchiveOrFail bytes of
42− Right archive -> archiveToEPUB opts $ archive
42+ Right archive -> archiveToEPUB opts archive
4343 Left _ -> throwError $ PandocParseError "Couldn't extract ePub file"
4444
4545-- runEPUB :: Except PandocError a -> Either PandocError a
@@ -61,7 +61,7 @@ archiveToEPUB os archive = do
6161 Pandoc _ bs <-
6262 foldM' (\a b -> ((a <>) . walk (prependHash escapedSpine))
6363 `liftM` parseSpineElem root b) mempty spine
64− let ast = coverDoc <> (Pandoc meta bs)
64+ let ast = coverDoc <> Pandoc meta bs
6565 fetchImages (M.elems items) root archive ast
6666 return ast
6767 where
@@ -79,7 +79,7 @@ archiveToEPUB os archive = do
7979 return $ fixInternalReferences path html
8080 mimeToReader s _ (unEscapeString -> path)
8181 | s `elem` imageMimes = return $ imageToPandoc path
82− | otherwise = return $ mempty
82+ | otherwise = return mempty
8383
8484-- paths should be absolute when this function is called
8585-- renameImages should do this
@@ -122,7 +122,7 @@ parseManifest content = do
122122 let items = findChildren (dfName "item") manifest
123123 r <- mapM parseItem items
124124 let cover = findAttr (emptyName "href") =<< filterChild findCover manifest
125− return (cover, (M.fromList r))
125+ return (cover, M.fromList r)
126126 where
127127 findCover e = maybe False (isInfixOf "cover-image")
128128 (findAttr (emptyName "properties") e)
@@ -136,7 +136,7 @@ parseSpine :: PandocMonad m => Items -> Element -> m [(FilePath, MimeType)]
136136parseSpine is e = do
137137 spine <- findElementE (dfName "spine") e
138138 let itemRefs = findChildren (dfName "itemref") spine
139− mapM (mkE "parseSpine" . (flip M.lookup is)) $ mapMaybe parseItemRef itemRefs
139+ mapM (mkE "parseSpine" . flip M.lookup is) $ mapMaybe parseItemRef itemRefs
140140 where
141141 parseItemRef ref = do
142142 let linear = maybe True (== "yes") (findAttr (emptyName "linear") ref)
@@ -167,21 +167,21 @@ getManifest archive = do
167167 docElem <- (parseXMLDocE . UTF8.toStringLazy . fromEntry) metaEntry
168168 let namespaces = mapMaybe attrToNSPair (elAttribs docElem)
169169 ns <- mkE "xmlns not in namespaces" (lookup "xmlns" namespaces)
170− as <- liftM ((map attrToPair) . elAttribs)
170+ as <- fmap (map attrToPair . elAttribs)
171171 (findElementE (QName "rootfile" (Just ns) Nothing) docElem)
172172 manifestFile <- mkE "Root not found" (lookup "full-path" as)
173173 let rootdir = dropFileName manifestFile
174174 --mime <- lookup "media-type" as
175175 manifest <- findEntryByPathE manifestFile archive
176− liftM ((,) rootdir) (parseXMLDocE . UTF8.toStringLazy . fromEntry $ manifest)
176+ fmap ((,) rootdir) (parseXMLDocE . UTF8.toStringLazy . fromEntry $ manifest)
177177
178178-- Fixup
179179
180180fixInternalReferences :: FilePath -> Pandoc -> Pandoc
181181fixInternalReferences pathToFile =
182− (walk $ renameImages root)
183− . (walk $ fixBlockIRs filename)
184− . (walk $ fixInlineIRs filename)
182+ walk (renameImages root)
183+ . walk (fixBlockIRs filename)
184+ . walk (fixInlineIRs filename)
185185 where
186186 (root, escapeURI -> filename) = splitFileName pathToFile
187187
src/Text/Pandoc/Readers/Haddock.hs+1−1
@@ -142,7 +142,7 @@ makeExample prompt expression result =
142142 <> B.space
143143 <> B.codeWith ([], ["haskell","expr"], []) (trim expression)
144144 <> B.linebreak
145− <> (mconcat $ intersperse B.linebreak $ map coder result')
145+ <> mconcat (intersperse B.linebreak $ map coder result')
146146 where
147147 -- 1. drop trailing whitespace from the prompt, remember the prefix
148148 prefix = takeWhile (`elem` " \t") prompt
src/Text/Pandoc/Readers/LaTeX.hs+34−34
@@ -107,7 +107,7 @@ parseLaTeX = do
107107 (if bottomLevel < 1
108108 then walk (adjustHeaders (1 - bottomLevel))
109109 else id) $
110− walk (resolveRefs (sLabels st)) $ doc'
110+ walk (resolveRefs (sLabels st)) doc'
111111 return $ Pandoc meta bs'
112112
113113resolveRefs :: M.Map String [Inline] -> Inline -> Inline
@@ -246,7 +246,7 @@ rawLaTeXParser parser = do
246246 case res of
247247 Left _ -> mzero
248248 Right (raw, st) -> do
249− updateState (updateMacros ((sMacros st) <>))
249+ updateState (updateMacros (sMacros st <>))
250250 takeP (T.length (untokenize raw))
251251
252252applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
@@ -333,7 +333,7 @@ totoks pos t =
333333 : totoks (incSourceColumn pos
334334 (1 + T.length ws + T.length ss)) rest'''
335335 | d == '\t' || d == '\n' ->
336− Tok pos Symbol ("\\")
336+ Tok pos Symbol "\\"
337337 : totoks (incSourceColumn pos 1) rest
338338 | otherwise ->
339339 Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d])
@@ -403,7 +403,7 @@ satisfyTok f =
403403doMacros :: PandocMonad m => Int -> LP m ()
404404doMacros n = do
405405 verbatimMode <- sVerbatimMode <$> getState
406− when (not verbatimMode) $ do
406+ unless verbatimMode $ do
407407 inp <- getInput
408408 case inp of
409409 Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
@@ -543,7 +543,7 @@ bgroup = try $ do
543543 symbol '{' <|> controlSeq "bgroup" <|> controlSeq "begingroup"
544544
545545egroup :: PandocMonad m => LP m Tok
546−egroup = (symbol '}' <|> controlSeq "egroup" <|> controlSeq "endgroup")
546+egroup = symbol '}' <|> controlSeq "egroup" <|> controlSeq "endgroup"
547547
548548grouped :: (PandocMonad m, Monoid a) => LP m a -> LP m a
549549grouped parser = try $ do
@@ -577,7 +577,7 @@ dimenarg :: PandocMonad m => LP m Text
577577dimenarg = try $ do
578578 ch <- option False $ True <$ symbol '='
579579 Tok _ _ s <- satisfyTok isWordTok
580− guard $ (T.take 2 (T.reverse s)) `elem`
580+ guard $ T.take 2 (T.reverse s) `elem`
581581 ["pt","pc","in","bp","cm","mm","dd","cc","sp"]
582582 let num = T.take (T.length s - 2) s
583583 guard $ T.length num > 0
@@ -633,7 +633,7 @@ mkImage options src = do
633633 _ -> return $ imageWith attr src "" alt
634634
635635doxspace :: PandocMonad m => LP m Inlines
636−doxspace = do
636+doxspace =
637637 (space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
638638 where startsWithLetter (Tok _ Word t) =
639639 case T.uncons t of
@@ -662,22 +662,22 @@ lit = pure . str
662662
663663removeDoubleQuotes :: Text -> Text
664664removeDoubleQuotes t =
665− maybe t id $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
665+ Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
666666
667667doubleQuote :: PandocMonad m => LP m Inlines
668−doubleQuote = do
668+doubleQuote =
669669 quoted' doubleQuoted (try $ count 2 $ symbol '`')
670− (void $ try $ count 2 $ symbol '\'')
670+ (void $ try $ count 2 $ symbol '\'')
671671 <|> quoted' doubleQuoted ((:[]) <$> symbol '“') (void $ symbol '”')
672672 -- the following is used by babel for localized quotes:
673673 <|> quoted' doubleQuoted (try $ sequence [symbol '"', symbol '`'])
674674 (void $ try $ sequence [symbol '"', symbol '\''])
675675
676676singleQuote :: PandocMonad m => LP m Inlines
677−singleQuote = do
677+singleQuote =
678678 quoted' singleQuoted ((:[]) <$> symbol '`')
679− (try $ symbol '\'' >>
680− notFollowedBy (satisfyTok startsWithLetter))
679+ (try $ symbol '\'' >>
680+ notFollowedBy (satisfyTok startsWithLetter))
681681 <|> quoted' singleQuoted ((:[]) <$> symbol '‘')
682682 (try $ symbol '’' >>
683683 notFollowedBy (satisfyTok startsWithLetter))
@@ -726,8 +726,8 @@ doAcronymPlural form = do
726726 acro <- braced
727727 plural <- lit "s"
728728 return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
729− ("acronym-form", "plural+" ++ form)]) $ mconcat
730− $ [str $ toksToString acro, plural]]
729+ ("acronym-form", "plural+" ++ form)]) $
730+ mconcat [str $ toksToString acro, plural]]
731731
732732doverb :: PandocMonad m => LP m Inlines
733733doverb = do
@@ -748,7 +748,7 @@ verbTok stopchar = do
748748 let (t1, t2) = T.splitAt i txt
749749 inp <- getInput
750750 setInput $ Tok (incSourceColumn pos i) Symbol (T.singleton stopchar)
751− : (totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2)) ++ inp
751+ : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp
752752 return $ Tok pos toktype t1
753753
754754dolstinline :: PandocMonad m => LP m Inlines
@@ -773,8 +773,8 @@ keyval = try $ do
773773 val <- option [] $ do
774774 symbol '='
775775 optional sp
776− braced <|> (many1 (satisfyTok isWordTok <|> satisfyTok isSpecSym
777− <|> anyControlSeq))
776+ braced <|> many1 (satisfyTok isWordTok <|> satisfyTok isSpecSym
777+ <|> anyControlSeq)
778778 optional sp
779779 optional (symbol ',')
780780 optional sp
@@ -1020,10 +1020,10 @@ dollarsMath = do
10201020 contents <- trim . toksToString <$>
10211021 many (notFollowedBy (symbol '$') >> anyTok)
10221022 if display
1023− then do
1023+ then
10241024 mathDisplay contents <$ try (symbol '$' >> symbol '$')
1025− <|> (guard (null contents) >> return (mathInline ""))
1026− else mathInline contents <$ (symbol '$')
1025+ <|> (guard (null contents) >> return (mathInline ""))
1026+ else mathInline contents <$ symbol '$'
10271027
10281028-- citations
10291029
@@ -1041,7 +1041,7 @@ simpleCiteArgs :: PandocMonad m => LP m [Citation]
10411041simpleCiteArgs = try $ do
10421042 first <- optionMaybe $ toList <$> opt
10431043 second <- optionMaybe $ toList <$> opt
1044− keys <- try $ bgroup *> (manyTill citationLabel egroup)
1044+ keys <- try $ bgroup *> manyTill citationLabel egroup
10451045 let (pre, suf) = case (first , second ) of
10461046 (Just s , Nothing) -> (mempty, s )
10471047 (Just s , Just t ) -> (s , t )
@@ -1080,7 +1080,7 @@ cites mode multi = try $ do
10801080citation :: PandocMonad m => String -> CitationMode -> Bool -> LP m Inlines
10811081citation name mode multi = do
10821082 (c,raw) <- withRaw $ cites mode multi
1083− return $ cite c (rawInline "latex" $ "\\" ++ name ++ (toksToString raw))
1083+ return $ cite c (rawInline "latex" $ "\\" ++ name ++ toksToString raw)
10841084
10851085handleCitationPart :: Inlines -> [Citation]
10861086handleCitationPart ils =
@@ -1139,7 +1139,7 @@ singleChar = try $ do
11391139 then do
11401140 let (t1, t2) = (T.take 1 t, T.drop 1 t)
11411141 inp <- getInput
1142− setInput $ (Tok (incSourceColumn pos 1) toktype t2) : inp
1142+ setInput $ Tok (incSourceColumn pos 1) toktype t2 : inp
11431143 return $ Tok pos toktype t1
11441144 else return $ Tok pos toktype t
11451145
@@ -1606,7 +1606,7 @@ getRawCommand name txt = do
16061606 void braced
16071607 skipopts
16081608 void $ count 4 braced
1609− "def" -> do
1609+ "def" ->
16101610 void $ manyTill anyTok braced
16111611 _ -> do
16121612 skipangles
@@ -1715,14 +1715,14 @@ inlines = mconcat <$> many inline
17151715-- block elements:
17161716
17171717begin_ :: PandocMonad m => Text -> LP m ()
1718−begin_ t = (try $ do
1718+begin_ t = try (do
17191719 controlSeq "begin"
17201720 spaces
17211721 txt <- untokenize <$> braced
17221722 guard (t == txt)) <?> ("\\begin{" ++ T.unpack t ++ "}")
17231723
17241724end_ :: PandocMonad m => Text -> LP m ()
1725−end_ t = (try $ do
1725+end_ t = try (do
17261726 controlSeq "end"
17271727 spaces
17281728 txt <- untokenize <$> braced
@@ -1766,7 +1766,7 @@ insertIncluded :: PandocMonad m
17661766insertIncluded dirs f = do
17671767 pos <- getPosition
17681768 containers <- getIncludeFiles <$> getState
1769− when (f `elem` containers) $ do
1769+ when (f `elem` containers) $
17701770 throwError $ PandocParseError $ "Include file loop at " ++ show pos
17711771 updateState $ addIncludeFile f
17721772 mbcontents <- readFileFromDirs dirs f
@@ -1800,7 +1800,7 @@ authors = try $ do
18001800 addMeta "author" (map trimInlines auths)
18011801
18021802macroDef :: PandocMonad m => LP m Blocks
1803−macroDef = do
1803+macroDef =
18041804 mempty <$ ((commandDef <|> environmentDef) <* doMacros 0)
18051805 where commandDef = do
18061806 (name, macro') <- newcommand <|> letmacro <|> defmacro
@@ -2177,9 +2177,9 @@ fancyverbEnv name = do
21772177 codeBlockWith attr <$> verbEnv name
21782178
21792179obeylines :: PandocMonad m => LP m Blocks
2180−obeylines = do
2180+obeylines =
21812181 para . fromList . removeLeadingTrailingBreaks .
2182− walk softBreakToHard . toList <$> env "obeylines" inlines
2182+ walk softBreakToHard . toList <$> env "obeylines" inlines
21832183 where softBreakToHard SoftBreak = LineBreak
21842184 softBreakToHard x = x
21852185 removeLeadingTrailingBreaks = reverse . dropWhile isLineBreak .
@@ -2368,7 +2368,7 @@ splitWordTok :: PandocMonad m => LP m ()
23682368splitWordTok = do
23692369 inp <- getInput
23702370 case inp of
2371− (Tok spos Word t : rest) -> do
2371+ (Tok spos Word t : rest) ->
23722372 setInput $ map (Tok spos Symbol . T.singleton) (T.unpack t) ++ rest
23732373 _ -> return ()
23742374
@@ -2433,9 +2433,9 @@ parseTableRow envname prefsufs = do
24332433 suffpos <- getPosition
24342434 option [] (count 1 amp)
24352435 return $ map (setpos prefpos) pref ++ contents ++ map (setpos suffpos) suff
2436− rawcells <- sequence (map celltoks prefsufs)
2436+ rawcells <- mapM celltoks prefsufs
24372437 oldInput <- getInput
2438− cells <- sequence $ map (\ts -> setInput ts >> parseTableCell) rawcells
2438+ cells <- mapM (\ts -> setInput ts >> parseTableCell) rawcells
24392439 setInput oldInput
24402440 spaces
24412441 let numcells = length cells
src/Text/Pandoc/Readers/LaTeX/Types.hs−1
@@ -49,4 +49,3 @@ data ExpansionPoint = ExpandWhenDefined | ExpandWhenUsed
4949
5050data Macro = Macro ExpansionPoint Int (Maybe [Tok]) [Tok]
5151 deriving Show
52−
src/Text/Pandoc/Readers/Markdown.hs+33−37
@@ -74,7 +74,7 @@ readMarkdown :: PandocMonad m
7474 -> Text -- ^ String to parse (assuming @'\n'@ line endings)
7575 -> m Pandoc
7676readMarkdown opts s = do
77− parsed <- (readWithM parseMarkdown) def{ stateOptions = opts }
77+ parsed <- readWithM parseMarkdown def{ stateOptions = opts }
7878 (T.unpack (crFilter s) ++ "\n\n")
7979 case parsed of
8080 Right result -> return result
@@ -162,7 +162,7 @@ charsInBalancedBrackets openBrackets =
162162 (char '[' >> charsInBalancedBrackets (openBrackets + 1))
163163 <|> (char ']' >> charsInBalancedBrackets (openBrackets - 1))
164164 <|> (( (() <$ code)
165− <|> (() <$ (escapedChar'))
165+ <|> (() <$ escapedChar')
166166 <|> (newline >> notFollowedBy blankline)
167167 <|> skipMany1 (noneOf "[]`\n\\")
168168 <|> (() <$ count 1 (oneOf "`\\"))
@@ -241,7 +241,7 @@ yamlMetaBlock = try $ do
241241 case Yaml.decodeEither' $ UTF8.fromString rawYaml of
242242 Right (Yaml.Object hashmap) -> do
243243 let alist = H.toList hashmap
244− mapM_ (\(k, v) -> do
244+ mapM_ (\(k, v) ->
245245 if ignorable k
246246 then return ()
247247 else do
@@ -320,7 +320,7 @@ yamlToMeta (Yaml.Array xs) = do
320320 return $ B.toMetaValue xs''
321321yamlToMeta (Yaml.Object o) = do
322322 let alist = H.toList o
323− foldM (\m (k,v) -> do
323+ foldM (\m (k,v) ->
324324 if ignorable k
325325 then return m
326326 else do
@@ -353,7 +353,7 @@ kvPair allowEmpty = try $ do
353353 (try $ newline >> lookAhead (blankline <|> nonspaceChar))
354354 guard $ allowEmpty || not (null val)
355355 let key' = concat $ words $ map toLower key
356− let val' = MetaBlocks $ B.toList $ B.plain $ B.text $ val
356+ let val' = MetaBlocks $ B.toList $ B.plain $B.text val
357357 return (key',val')
358358
359359parseMarkdown :: PandocMonad m => MarkdownParser m Pandoc
@@ -364,8 +364,7 @@ parseMarkdown = do
364364 -- check for notes with no corresponding note references
365365 let notesUsed = stateNoteRefs st
366366 let notesDefined = M.keys (stateNotes' st)
367− mapM_ (\n -> unless (n `Set.member` notesUsed) $ do
368− -- lookup to get sourcepos
367+ mapM_ (\n -> unless (n `Set.member` notesUsed) $
369368 case M.lookup n (stateNotes' st) of
370369 Just (pos, _) -> report (NoteDefinedButNotUsed n pos)
371370 Nothing -> throwError $
@@ -384,7 +383,7 @@ referenceKey = try $ do
384383 (_,raw) <- reference
385384 char ':'
386385 skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[')
387− let sourceURL = liftM unwords $ many $ try $ do
386+ let sourceURL = fmap unwords $ many $ try $ do
388387 skipMany spaceChar
389388 notFollowedBy' referenceTitle
390389 notFollowedBy' $ guardEnabled Ext_link_attributes >> attributes
@@ -533,7 +532,7 @@ atxChar = do
533532
534533atxHeader :: PandocMonad m => MarkdownParser m (F Blocks)
535534atxHeader = try $ do
536− level <- atxChar >>= many1 . char >>= return . length
535+ level <- fmap length (atxChar >>= many1 . char)
537536 notFollowedBy $ guardEnabled Ext_fancy_lists >>
538537 (char '.' <|> char ')') -- this would be a list
539538 guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
@@ -588,7 +587,7 @@ setextHeader = try $ do
588587 underlineChar <- oneOf setextHChars
589588 many (char underlineChar)
590589 blanklines
591− let level = (fromMaybe 0 $ findIndex (== underlineChar) setextHChars) + 1
590+ let level = fromMaybe 0 (findIndex (== underlineChar) setextHChars) + 1
592591 attr' <- registerHeader attr (runF text defaultParserState)
593592 guardDisabled Ext_implicit_header_references
594593 <|> registerImplicitHeader raw attr'
@@ -629,8 +628,7 @@ blockDelimiter f len = try $ do
629628 c <- lookAhead (satisfy f)
630629 case len of
631630 Just l -> count l (char c) >> many (char c) >> return l
632− Nothing -> count 3 (char c) >> many (char c) >>=
633− return . (+ 3) . length
631+ Nothing -> fmap ((+ 3) . length) (count 3 (char c) >> many (char c))
634632
635633attributes :: PandocMonad m => MarkdownParser m Attr
636634attributes = try $ do
@@ -794,7 +792,7 @@ blockQuote :: PandocMonad m => MarkdownParser m (F Blocks)
794792blockQuote = do
795793 raw <- emailBlockQuote
796794 -- parse the extracted block, which may contain various block elements:
797− contents <- parseFromString' parseBlocks $ (intercalate "\n" raw) ++ "\n\n"
795+ contents <- parseFromString' parseBlocks $ intercalate "\n" raw ++ "\n\n"
798796 return $ B.blockQuote <$> contents
799797
800798--
@@ -840,7 +838,7 @@ orderedListStart mbstydelim = try $ do
840838 return (num, style, delim))
841839
842840listStart :: PandocMonad m => MarkdownParser m ()
843−listStart = bulletListStart <|> (orderedListStart Nothing >> return ())
841+listStart = bulletListStart <|> (Control.Monad.void (orderedListStart Nothing))
844842
845843listLine :: PandocMonad m => Int -> MarkdownParser m String
846844listLine continuationIndent = try $ do
@@ -854,7 +852,7 @@ listLine continuationIndent = try $ do
854852listLineCommon :: PandocMonad m => MarkdownParser m String
855853listLineCommon = concat <$> manyTill
856854 ( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
857− <|> liftM snd (htmlTag isCommentTag)
855+ <|> fmap snd (htmlTag isCommentTag)
858856 <|> count 1 anyChar
859857 ) newline
860858
@@ -973,7 +971,7 @@ defRawBlock compact = try $ do
973971 <|> notFollowedBy defListMarker
974972 anyLine )
975973 rawlines <- many dline
976− cont <- liftM concat $ many $ try $ do
974+ cont <- fmap concat $ many $ try $ do
977975 trailing <- option "" blanklines
978976 ln <- indentSpaces >> notFollowedBy blankline >> anyLine
979977 lns <- many dline
@@ -984,7 +982,7 @@ defRawBlock compact = try $ do
984982definitionList :: PandocMonad m => MarkdownParser m (F Blocks)
985983definitionList = try $ do
986984 lookAhead (anyLine >>
987− optional (blankline >> notFollowedBy (table >> return ())) >>
985+ optional (blankline >> notFollowedBy (Control.Monad.void table)) >>
988986 -- don't capture table caption as def list!
989987 defListMarker)
990988 compactDefinitionList <|> normalDefinitionList
@@ -1052,7 +1050,7 @@ plain = fmap B.plain . trimInlinesF <$> inlines1
10521050htmlElement :: PandocMonad m => MarkdownParser m String
10531051htmlElement = rawVerbatimBlock
10541052 <|> strictHtmlBlock
1055− <|> liftM snd (htmlTag isBlockTag)
1053+ <|> fmap snd (htmlTag isBlockTag)
10561054
10571055htmlBlock :: PandocMonad m => MarkdownParser m (F Blocks)
10581056htmlBlock = do
@@ -1183,17 +1181,17 @@ simpleTableHeader headless = try $ do
11831181 let (lengths, lines') = unzip dashes
11841182 let indices = scanl (+) (length initSp) lines'
11851183 -- If no header, calculate alignment on basis of first row of text
1186− rawHeads <- liftM (tail . splitStringByIndices (init indices)) $
1184+ rawHeads <- fmap (tail . splitStringByIndices (init indices)) $
11871185 if headless
11881186 then lookAhead anyLine
11891187 else return rawContent
1190− let aligns = zipWith alignType (map (\a -> [a]) rawHeads) lengths
1188+ let aligns = zipWith alignType (map ((: [])) rawHeads) lengths
11911189 let rawHeads' = if headless
11921190 then replicate (length dashes) ""
11931191 else rawHeads
11941192 heads <- fmap sequence
1195− $ mapM (parseFromString' (mconcat <$> many plain))
1196− $ map trim rawHeads'
1193+ $
1194+ mapM ((parseFromString' (mconcat <$> many plain)).trim) rawHeads'
11971195 return (heads, aligns, indices)
11981196
11991197-- Returns an alignment type for a table, based on a list of strings
@@ -1295,7 +1293,7 @@ multilineTableHeader headless = try $ do
12951293 let (lengths, lines') = unzip dashes
12961294 let indices = scanl (+) (length initSp) lines'
12971295 rawHeadsList <- if headless
1298− then liftM (map (:[]) . tail .
1296+ then fmap (map (:[]) . tail .
12991297 splitStringByIndices (init indices)) $ lookAhead anyLine
13001298 else return $ transpose $ map
13011299 (tail . splitStringByIndices (init indices))
@@ -1305,8 +1303,7 @@ multilineTableHeader headless = try $ do
13051303 then replicate (length dashes) ""
13061304 else map (unlines . map trim) rawHeadsList
13071305 heads <- fmap sequence $
1308− mapM (parseFromString' (mconcat <$> many plain)) $
1309− map trim rawHeads
1306+ mapM ((parseFromString' (mconcat <$> many plain)).trim) rawHeads
13101307 return (heads, aligns, indices)
13111308
13121309-- Parse a grid table: starts with row of '-' on top, then header
@@ -1345,7 +1342,7 @@ pipeTable = try $ do
13451342 fromIntegral (len + 1) / fromIntegral numColumns)
13461343 seplengths
13471344 else replicate (length aligns) 0.0
1348− return $ (aligns, widths, heads', sequence lines'')
1345+ return (aligns, widths, heads', sequence lines'')
13491346
13501347sepPipe :: PandocMonad m => MarkdownParser m ()
13511348sepPipe = try $ do
@@ -1363,7 +1360,7 @@ pipeTableRow = try $ do
13631360 <|> void (noneOf "|\n\r")
13641361 let cellContents = ((trim . snd) <$> withRaw (many chunk)) >>=
13651362 parseFromString' pipeTableCell
1366− cells <- cellContents `sepEndBy1` (char '|')
1363+ cells <- cellContents `sepEndBy1` char '|'
13671364 -- surrounding pipes needed for a one-column table:
13681365 guard $ not (length cells == 1 && not openPipe)
13691366 blankline
@@ -1383,7 +1380,7 @@ pipeTableHeaderPart = try $ do
13831380 right <- optionMaybe (char ':')
13841381 skipMany spaceChar
13851382 let len = length pipe + maybe 0 (const 1) left + maybe 0 (const 1) right
1386− return $
1383+ return
13871384 ((case (left,right) of
13881385 (Nothing,Nothing) -> AlignDefault
13891386 (Just _,Nothing) -> AlignLeft
@@ -1412,10 +1409,10 @@ tableWith headerParser rowParser lineParser footerParser = try $ do
14121409 lines' <- fmap sequence $ rowParser indices `sepEndBy1` lineParser
14131410 footerParser
14141411 numColumns <- getOption readerColumns
1415− let widths = if (indices == [])
1412+ let widths = if indices == []
14161413 then replicate (length aligns) 0.0
14171414 else widthsFromIndices numColumns indices
1418− return $ (aligns, widths, heads, lines')
1415+ return (aligns, widths, heads, lines')
14191416
14201417table :: PandocMonad m => MarkdownParser m (F Blocks)
14211418table = try $ do
@@ -1573,7 +1570,7 @@ enclosure c = do
15731570 <|> (guard =<< notAfterString)
15741571 cs <- many1 (char c)
15751572 (return (B.str cs) <>) <$> whitespace
1576− <|> do
1573+ <|>
15771574 case length cs of
15781575 3 -> three c
15791576 2 -> two c mempty
@@ -1723,7 +1720,7 @@ source = do
17231720 skipSpaces
17241721 let urlChunk =
17251722 try parenthesizedChars
1726− <|> (notFollowedBy (oneOf " )") >> (count 1 litChar))
1723+ <|> (notFollowedBy (oneOf " )") >> count 1 litChar)
17271724 <|> try (many1 spaceChar <* notFollowedBy (oneOf "\"')"))
17281725 let sourceURL = (unwords . words . concat) <$> many urlChunk
17291726 let betweenAngles = try $
@@ -1892,8 +1889,8 @@ rawConTeXtEnvironment :: PandocMonad m => ParserT [Char] st m String
18921889rawConTeXtEnvironment = try $ do
18931890 string "\\start"
18941891 completion <- inBrackets (letter <|> digit <|> spaceChar)
1895− <|> (many1 letter)
1896− contents <- manyTill (rawConTeXtEnvironment <|> (count 1 anyChar))
1892+ <|> many1 letter
1893+ contents <- manyTill (rawConTeXtEnvironment <|> count 1 anyChar)
18971894 (try $ string "\\stop" >> string completion)
18981895 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
18991896
@@ -1999,10 +1996,9 @@ emoji = try $ do
19991996cite :: PandocMonad m => MarkdownParser m (F Inlines)
20001997cite = do
20011998 guardEnabled Ext_citations
2002− citations <- textualCite
1999+ textualCite
20032000 <|> do (cs, raw) <- withRaw normalCite
20042001 return $ (flip B.cite (B.text raw)) <$> cs
2005− return citations
20062002
20072003textualCite :: PandocMonad m => MarkdownParser m (F Inlines)
20082004textualCite = try $ do
@@ -2076,7 +2072,7 @@ suffix = try $ do
20762072
20772073prefix :: PandocMonad m => MarkdownParser m (F Inlines)
20782074prefix = trimInlinesF . mconcat <$>
2079− manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
2075+ manyTill inline (char ']' <|> fmap (const ']') (lookAhead citeKey))
20802076
20812077citeList :: PandocMonad m => MarkdownParser m (F [Citation])
20822078citeList = fmap sequence $ sepBy1 citation (try $ char ';' >> spnl)
src/Text/Pandoc/Readers/Muse.hs+9−9
@@ -137,7 +137,7 @@ parseHtmlContentWithAttrs tag parser = do
137137 endOfContent = try $ skipMany blankline >> skipSpaces >> eof
138138
139139parseHtmlContent :: PandocMonad m => String -> MuseParser m a -> MuseParser m [a]
140−parseHtmlContent tag p = liftM snd (parseHtmlContentWithAttrs tag p)
140+parseHtmlContent tag p = fmap snd (parseHtmlContentWithAttrs tag p)
141141
142142--
143143-- directive parsers
@@ -213,7 +213,7 @@ header = try $ do
213213 st <- stateParserContext <$> getState
214214 q <- stateQuoteContext <$> getState
215215 getPosition >>= \pos -> guard (st == NullState && q == NoQuote && sourceColumn pos == 1)
216− level <- liftM length $ many1 $ char '*'
216+ level <- fmap length $ many1 $ char '*'
217217 guard $ level <= 5
218218 spaceChar
219219 content <- trimInlinesF . mconcat <$> manyTill inline eol
@@ -240,7 +240,7 @@ exampleTag = do
240240 chop = lchop . rchop
241241
242242literal :: PandocMonad m => MuseParser m (F Blocks)
243−literal = liftM (return . rawBlock) $ htmlElement "literal"
243+literal = fmap (return . rawBlock) $ htmlElement "literal"
244244 where
245245 format (_, _, kvs) = fromMaybe "html" $ lookup "format" kvs
246246 rawBlock (attrs, content) = B.rawBlock (format attrs) content
@@ -268,7 +268,7 @@ quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
268268divTag :: PandocMonad m => MuseParser m (F Blocks)
269269divTag = do
270270 (attrs, content) <- parseHtmlContentWithAttrs "div" block
271− return $ (B.divWith attrs) <$> mconcat content
271+ return $ B.divWith attrs <$> mconcat content
272272
273273verseLine :: PandocMonad m => MuseParser m String
274274verseLine = do
@@ -296,7 +296,7 @@ para :: PandocMonad m => MuseParser m (F Blocks)
296296para = do
297297 indent <- length <$> many spaceChar
298298 let f = if indent >= 2 && indent < 6 then B.blockQuote else id
299− liftM (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
299+ fmap (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
300300 where
301301 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
302302 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
@@ -481,7 +481,7 @@ museAppendElement tbl element =
481481 return tbl{ museTableCaption = inlines' }
482482
483483tableCell :: PandocMonad m => MuseParser m (F Blocks)
484−tableCell = try $ liftM B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
484+tableCell = try $ fmap B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
485485 where cellEnd = try $ void (many1 spaceChar >> char '|') <|> eol
486486
487487tableElements :: PandocMonad m => MuseParser m [MuseTableElement]
@@ -575,7 +575,7 @@ footnote = try $ do
575575 return $ B.note contents'
576576
577577whitespace :: PandocMonad m => MuseParser m (F Inlines)
578−whitespace = liftM return (lb <|> regsp)
578+whitespace = fmap return (lb <|> regsp)
579579 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
580580 regsp = try $ skipMany1 spaceChar >> return B.space
581581
@@ -655,10 +655,10 @@ codeTag = do
655655 return $ return $ B.codeWith attrs $ fromEntities content
656656
657657str :: PandocMonad m => MuseParser m (F Inlines)
658−str = liftM (return . B.str) (many1 alphaNum <|> count 1 characterReference)
658+str = fmap (return . B.str) (many1 alphaNum <|> count 1 characterReference)
659659
660660symbol :: PandocMonad m => MuseParser m (F Inlines)
661−symbol = liftM (return . B.str) $ count 1 nonspaceChar
661+symbol = fmap (return . B.str) $ count 1 nonspaceChar
662662
663663link :: PandocMonad m => MuseParser m (F Inlines)
664664link = try $ do
src/Text/Pandoc/Readers/Native.hs−1
@@ -69,4 +69,3 @@ readInlines s = maybe ((:[]) <$> readInline s) Right (safeRead (unpack s))
6969
7070readInline :: Text -> Either PandocError Inline
7171readInline s = maybe (Left . PandocParseError $ "Could not read: " ++ unpack s) Right (safeRead (unpack s))
72−
src/Text/Pandoc/Readers/OPML.hs+7−8
@@ -4,6 +4,7 @@ import Control.Monad.State.Strict
44import Data.Char (toUpper)
55import Data.Default
66import Data.Generics
7+import Data.Maybe (fromMaybe)
78import Data.Text (Text, pack, unpack)
89import Text.HTML.TagSoup.Entity (lookupEntity)
910import Text.Pandoc.Builder
@@ -32,9 +33,9 @@ instance Default OPMLState where
3233
3334readOPML :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
3435readOPML _ inp = do
35− (bs, st') <- flip runStateT def
36+ (bs, st') <- runStateT
3637 (mapM parseBlock $ normalizeTree $
37− parseXML (unpack (crFilter inp)))
38+ parseXML (unpack (crFilter inp))) def
3839 return $
3940 setTitle (opmlDocTitle st') $
4041 setAuthors (opmlDocAuthors st') $
@@ -62,9 +63,7 @@ convertEntity e = maybe (map toUpper e) id (lookupEntity e)
6263-- convenience function to get an attribute value, defaulting to ""
6364attrValue :: String -> Element -> String
6465attrValue attr elt =
65− case lookupAttrBy (\x -> qName x == attr) (elAttribs elt) of
66− Just z -> z
67− Nothing -> ""
66+ fromMaybe "" (lookupAttrBy (\x -> qName x == attr) (elAttribs elt))
6867
6968-- exceptT :: PandocMonad m => Either PandocError a -> OPML m a
7069-- exceptT = either throwError return
@@ -73,13 +72,13 @@ asHtml :: PandocMonad m => String -> OPML m Inlines
7372asHtml s =
7473 (\(Pandoc _ bs) -> case bs of
7574 [Plain ils] -> fromList ils
76− _ -> mempty) <$> (lift $ readHtml def (pack s))
75+ _ -> mempty) <$> lift (readHtml def (pack s))
7776
7877asMarkdown :: PandocMonad m => String -> OPML m Blocks
79−asMarkdown s = (\(Pandoc _ bs) -> fromList bs) <$> (lift $ readMarkdown def (pack s))
78+asMarkdown s = (\(Pandoc _ bs) -> fromList bs) <$> lift (readMarkdown def (pack s))
8079
8180getBlocks :: PandocMonad m => Element -> OPML m Blocks
82−getBlocks e = mconcat <$> (mapM parseBlock $ elContent e)
81+getBlocks e = mconcat <$> mapM parseBlock (elContent e)
8382
8483parseBlock :: PandocMonad m => Content -> OPML m Blocks
8584parseBlock (Elem e) =
src/Text/Pandoc/Readers/Odt/Arrows/State.hs+3−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE Arrows #-}
1+
22{-# LANGUAGE FlexibleInstances #-}
33{-# LANGUAGE TupleSections #-}
44{-
@@ -139,7 +139,7 @@ iterateS :: (Foldable f, MonadPlus m)
139139 => ArrowState s x y
140140 -> ArrowState s (f x) (m y)
141141iterateS a = ArrowState $ \(s,f) -> foldr a' (s,mzero) f
142− where a' x (s',m) = second ((mplus m).return) $ runArrowState a (s',x)
142+ where a' x (s',m) = second (mplus m.return) $ runArrowState a (s',x)
143143
144144-- | Fold a state arrow through something 'Foldable'. Collect the results in a
145145-- 'MonadPlus'.
@@ -147,7 +147,7 @@ iterateSL :: (Foldable f, MonadPlus m)
147147 => ArrowState s x y
148148 -> ArrowState s (f x) (m y)
149149iterateSL a = ArrowState $ \(s,f) -> foldl a' (s,mzero) f
150− where a' (s',m) x = second ((mplus m).return) $ runArrowState a (s',x)
150+ where a' (s',m) x = second (mplus m.return) $ runArrowState a (s',x)
151151
152152
153153-- | Fold a fallible state arrow through something 'Foldable'.
src/Text/Pandoc/Readers/Odt/Base.hs+1−2
@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards #-}
1+
22
33{-
44Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>
@@ -40,4 +40,3 @@ type OdtConverterState s = XMLConverterState Namespace s
4040type XMLReader s a b = FallibleXMLConverter Namespace s a b
4141
4242type XMLReaderSafe s a b = XMLConverter Namespace s a b
43−
src/Text/Pandoc/Readers/Odt/Generic/Fallible.hs+2−2
@@ -1,4 +1,4 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1+
22
33{-
44Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>
@@ -121,6 +121,6 @@ newtype SuccessList a = SuccessList { collectNonFailing :: [a] }
121121 deriving ( Eq, Ord, Show )
122122
123123instance ChoiceVector SuccessList where
124− spreadChoice = Right . SuccessList . (foldr unTagRight []) . collectNonFailing
124+ spreadChoice = Right . SuccessList . foldr unTagRight [] . collectNonFailing
125125 where unTagRight (Right x) = (x:)
126126 unTagRight _ = id
src/Text/Pandoc/Readers/Odt/Generic/Utils.hs+2−2
@@ -1,5 +1,5 @@
1−{-# LANGUAGE PatternGuards #-}
2−{-# LANGUAGE TupleSections #-}
1+
2+
33{-# LANGUAGE TypeOperators #-}
44{-# LANGUAGE ViewPatterns #-}
55
src/Text/Pandoc/Readers/Textile.hs+1−1
@@ -110,7 +110,7 @@ noteBlock = try $ do
110110 startPos <- getPosition
111111 ref <- noteMarker
112112 optional blankline
113− contents <- liftM unlines $ many1Till anyLine (blanklines <|> noteBlock)
113+ contents <- fmap unlines $ many1Till anyLine (blanklines <|> noteBlock)
114114 endPos <- getPosition
115115 let newnote = (ref, contents ++ "\n")
116116 st <- getState
src/Text/Pandoc/Readers/TikiWiki.hs+50−54
@@ -22,7 +22,6 @@ module Text.Pandoc.Readers.TikiWiki ( readTikiWiki
2222import Control.Monad
2323import Control.Monad.Except (throwError)
2424import qualified Data.Foldable as F
25−import Data.List (intercalate)
2625import Data.Maybe (fromMaybe)
2726import Data.Text (Text)
2827import qualified Data.Text as T
@@ -58,7 +57,7 @@ tryMsg :: PandocMonad m => String -> TikiWikiParser m a -> TikiWikiParser m a
5857tryMsg msg p = try p <?> msg
5958
6059skip :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m ()
61−skip parser = parser >> return ()
60+skip parser = Control.Monad.void parser
6261
6362nested :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m a
6463nested p = do
@@ -88,7 +87,7 @@ block = do
8887 <|> blockElements
8988 <|> para
9089 skipMany blankline
91− when (verbosity >= INFO) $ do
90+ when (verbosity >= INFO) $
9291 trace (printf "line %d: %s" (sourceLine pos) (take 60 $ show $ B.toList res))
9392 return res
9493
@@ -112,7 +111,7 @@ hr = try $ do
112111 string "----"
113112 many (char '-')
114113 newline
115− return $ B.horizontalRule
114+ return B.horizontalRule
116115
117116-- ! header
118117--
@@ -122,18 +121,18 @@ hr = try $ do
122121--
123122header :: PandocMonad m => TikiWikiParser m B.Blocks
124123header = tryMsg "header" $ do
125− level <- many1 (char '!') >>= return . length
124+ level <- fmap length (many1 (char '!'))
126125 guard $ level <= 6
127126 skipSpaces
128127 content <- B.trimInlines . mconcat <$> manyTill inline newline
129128 attr <- registerHeader nullAttr content
130− return $ B.headerWith attr level $ content
129+ return $B.headerWith attr level content
131130
132131tableRow :: PandocMonad m => TikiWikiParser m [B.Blocks]
133132tableRow = try $ do
134133-- row <- sepBy1 (many1Till inline $ oneOf "\n|") (try $ string "|" <* notFollowedBy (oneOf "|\n"))
135134-- return $ map (B.plain . mconcat) row
136− row <- sepBy1 ((many1 $ noneOf "\n|") >>= parseColumn) (try $ string "|" <* notFollowedBy (oneOf "|\n"))
135+ row <- sepBy1 (many1 (noneOf "\n|") >>= parseColumn) (try $ string "|" <* notFollowedBy (oneOf "|\n"))
137136 return $ map B.plain row
138137 where
139138 parseColumn x = do
@@ -165,14 +164,14 @@ table = try $ do
165164 string "||"
166165 newline
167166 -- return $ B.simpleTable (headers rows) $ trace ("rows: " ++ (show rows)) rows
168− return $ B.simpleTable (headers rows) $ rows
167+ return $B.simpleTable (headers rows) rows
169168 where
170169 -- The headers are as many empty srings as the number of columns
171170 -- in the first row
172− headers rows = map (B.plain . B.str) $ take (length $ rows !! 0) $ repeat ""
171+ headers rows = map (B.plain . B.str) $replicate (length $ rows !! 0) ""
173172
174173para :: PandocMonad m => TikiWikiParser m B.Blocks
175−para = many1Till inline endOfParaElement >>= return . result . mconcat
174+para = fmap (result . mconcat) ( many1Till inline endOfParaElement)
176175 where
177176 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
178177 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
@@ -189,7 +188,7 @@ para = many1Till inline endOfParaElement >>= return . result . mconcat
189188--
190189definitionList :: PandocMonad m => TikiWikiParser m B.Blocks
191190definitionList = tryMsg "definitionList" $ do
192− elements <- many1 $ parseDefinitionListItem
191+ elements <-many1 parseDefinitionListItem
193192 return $ B.definitionList elements
194193 where
195194 parseDefinitionListItem :: PandocMonad m => TikiWikiParser m (B.Inlines, [B.Blocks])
@@ -197,7 +196,7 @@ definitionList = tryMsg "definitionList" $ do
197196 skipSpaces >> char ';' <* skipSpaces
198197 term <- many1Till inline $ char ':' <* skipSpaces
199198 line <- listItemLine 1
200− return $ (mconcat term, [B.plain line])
199+ return (mconcat term, [B.plain line])
201200
202201data ListType = None | Numbered | Bullet deriving (Ord, Eq, Show)
203202
@@ -233,15 +232,15 @@ mixedList = try $ do
233232-- figre out a fold or something.
234233fixListNesting :: [B.Blocks] -> [B.Blocks]
235234fixListNesting [] = []
236−fixListNesting (first:[]) = [recurseOnList first]
235+fixListNesting [first] = [recurseOnList first]
237236-- fixListNesting nestall | trace ("\n\nfixListNesting: " ++ (show nestall)) False = undefined
238237-- fixListNesting nestall@(first:second:rest) =
239238fixListNesting (first:second:rest) =
240239 let secondBlock = head $ B.toList second in
241240 case secondBlock of
242− BulletList _ -> fixListNesting $ [(mappend (recurseOnList first) (recurseOnList second))] ++ rest
243− OrderedList _ _ -> fixListNesting $ [(mappend (recurseOnList first) (recurseOnList second))] ++ rest
244− _ -> [recurseOnList first] ++ fixListNesting (second:rest)
241+ BulletList _ -> fixListNesting $ (mappend (recurseOnList first) (recurseOnList second)) : rest
242+ OrderedList _ _ -> fixListNesting $ (mappend (recurseOnList first) (recurseOnList second)) : rest
243+ _ -> recurseOnList first : fixListNesting (second:rest)
245244
246245-- This function walks the Block structure for fixListNesting,
247246-- because it's a bit complicated, what with converting to and from
@@ -249,7 +248,7 @@ fixListNesting (first:second:rest) =
249248recurseOnList :: B.Blocks -> B.Blocks
250249-- recurseOnList item | trace ("rOL: " ++ (show $ length $ B.toList item) ++ ", " ++ (show $ B.toList item)) False = undefined
251250recurseOnList items
252− | (length $ B.toList items) == 1 =
251+ | length (B.toList items) == 1 =
253252 let itemBlock = head $ B.toList items in
254253 case itemBlock of
255254 BulletList listItems -> B.bulletList $ fixListNesting $ map B.fromList listItems
@@ -272,11 +271,11 @@ recurseOnList items
272271-- sections.
273272spanFoldUpList :: ListNesting -> [(ListNesting, B.Blocks)] -> [B.Blocks]
274273spanFoldUpList _ [] = []
275−spanFoldUpList ln (first:[]) =
274+spanFoldUpList ln [first] =
276275 listWrap ln (fst first) [snd first]
277276spanFoldUpList ln (first:rest) =
278277 let (span1, span2) = span (splitListNesting (fst first)) rest
279− newTree1 = listWrap ln (fst first) $ [snd first] ++ spanFoldUpList (fst first) span1
278+ newTree1 = listWrap ln (fst first) $ snd first : spanFoldUpList (fst first) span1
280279 newTree2 = spanFoldUpList ln span2
281280 in
282281 newTree1 ++ newTree2
@@ -285,14 +284,13 @@ spanFoldUpList ln (first:rest) =
285284-- item, which is true if the second item is at a deeper nesting
286285-- level and of the same type.
287286splitListNesting :: ListNesting -> (ListNesting, B.Blocks) -> Bool
288−splitListNesting ln1 (ln2, _) =
289− if (lnnest ln1) < (lnnest ln2) then
290− True
291− else
292− if ln1 == ln2 then
293− True
294− else
295− False
287+splitListNesting ln1 (ln2, _)
288+ | (lnnest ln1) < (lnnest ln2) =
289+ True
290+ | ln1 == ln2 =
291+ True
292+ | otherwise =
293+ False
296294
297295-- If we've moved to a deeper nesting level, wrap the new level in
298296-- the appropriate type of list.
@@ -323,7 +321,7 @@ bulletItem = try $ do
323321 prefix <- many1 $ char '*'
324322 many1 $ char ' '
325323 content <- listItemLine (length prefix)
326− return $ (LN Bullet (length prefix), B.plain content)
324+ return (LN Bullet (length prefix), B.plain content)
327325
328326-- # Start each line
329327-- # with a number (1.).
@@ -335,17 +333,17 @@ numberedItem = try $ do
335333 prefix <- many1 $ char '#'
336334 many1 $ char ' '
337335 content <- listItemLine (length prefix)
338− return $ (LN Numbered (length prefix), B.plain content)
336+ return (LN Numbered (length prefix), B.plain content)
339337
340338listItemLine :: PandocMonad m => Int -> TikiWikiParser m B.Inlines
341−listItemLine nest = lineContent >>= parseContent >>= return
339+listItemLine nest = lineContent >>= parseContent
342340 where
343341 lineContent = do
344342 content <- anyLine
345343 continuation <- optionMaybe listContinuation
346− return $ filterSpaces content ++ "\n" ++ (maybe "" id continuation)
344+ return $ filterSpaces content ++ "\n" ++ maybe "" id continuation
347345 filterSpaces = reverse . dropWhile (== ' ') . reverse
348− listContinuation = string (take nest (repeat '+')) >> lineContent
346+ listContinuation = string (replicate nest '+') >> lineContent
349347 parseContent x = do
350348 parsed <- parseFromString (many1 inline) x
351349 return $ mconcat parsed
@@ -373,7 +371,7 @@ codeMacro = try $ do
373371 string ")}"
374372 body <- manyTill anyChar (try (string "{CODE}"))
375373 newline
376− if length rawAttrs > 0
374+ if not (null rawAttrs)
377375 then
378376 return $ B.codeBlockWith (mungeAttrs rawAttrs) body
379377 else
@@ -412,7 +410,7 @@ inline = choice [ whitespace
412410 ] <?> "inline"
413411
414412whitespace :: PandocMonad m => TikiWikiParser m B.Inlines
415−whitespace = (lb <|> regsp) >>= return
413+whitespace = (lb <|> regsp)
416414 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
417415 regsp = try $ skipMany1 spaceChar >> return B.space
418416
@@ -452,7 +450,7 @@ enclosed sep p = between sep (try $ sep <* endMarker) p
452450nestedInlines :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser m B.Inlines
453451nestedInlines end = innerSpace <|> nestedInline
454452 where
455− innerSpace = try $ whitespace <* (notFollowedBy end)
453+ innerSpace = try $ whitespace <* notFollowedBy end
456454 nestedInline = notFollowedBy whitespace >> nested inline
457455
458456-- {img attId="39" imalign="right" link="http://info.tikiwiki.org" alt="Panama Hat"}
@@ -470,13 +468,13 @@ image = try $ do
470468 let title = fromMaybe src $ lookup "desc" rawAttrs
471469 let alt = fromMaybe title $ lookup "alt" rawAttrs
472470 let classes = map fst $ filter (\(_,b) -> b == "" || b == "y") rawAttrs
473− if length src > 0
471+ if not (null src)
474472 then
475473 return $ B.imageWith ("", classes, rawAttrs) src title (B.str alt)
476474 else
477− return $ B.str $ " NOT SUPPORTED: image without src attribute BEGIN: {img " ++ (printAttrs rawAttrs) ++ "} :END "
475+ return $ B.str $ " NOT SUPPORTED: image without src attribute BEGIN: {img " ++ printAttrs rawAttrs ++ "} :END "
478476 where
479− printAttrs attrs = intercalate " " $ map (\(a, b) -> a ++ "=\"" ++ b ++ "\"") attrs
477+ printAttrs attrs = unwords $ map (\(a, b) -> a ++ "=\"" ++ b ++ "\"") attrs
480478
481479imageAttr :: PandocMonad m => TikiWikiParser m (String, String)
482480imageAttr = try $ do
@@ -491,11 +489,11 @@ imageAttr = try $ do
491489
492490-- __strong__
493491strong :: PandocMonad m => TikiWikiParser m B.Inlines
494−strong = try $ enclosed (string "__") nestedInlines >>= return . B.strong
492+strong = try $ fmap B.strong (enclosed (string "__") nestedInlines)
495493
496494-- ''emph''
497495emph :: PandocMonad m => TikiWikiParser m B.Inlines
498−emph = try $ enclosed (string "''") nestedInlines >>= return . B.emph
496+emph = try $ fmap B.emph (enclosed (string "''") nestedInlines)
499497
500498-- ~246~
501499escapedChar :: PandocMonad m => TikiWikiParser m B.Inlines
@@ -503,7 +501,7 @@ escapedChar = try $ do
503501 string "~"
504502 inner <- many1 $ oneOf "0123456789"
505503 string "~"
506− return $ B.str $ [(toEnum ((read inner) :: Int)) :: Char]
504+ return $B.str [(toEnum ((read inner) :: Int)) :: Char]
507505
508506-- UNSUPPORTED, as there doesn't seem to be any facility in calibre
509507-- for this
@@ -543,10 +541,10 @@ boxed = try $ do
543541
544542-- --text--
545543strikeout :: PandocMonad m => TikiWikiParser m B.Inlines
546−strikeout = try $ enclosed (string "--") nestedInlines >>= return . B.strikeout
544+strikeout = try $ fmap B.strikeout (enclosed (string "--") nestedInlines)
547545
548546nestedString :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser m String
549−nestedString end = innerSpace <|> (count 1 nonspaceChar)
547+nestedString end = innerSpace <|> count 1 nonspaceChar
550548 where
551549 innerSpace = try $ many1 spaceChar <* notFollowedBy end
552550
@@ -555,7 +553,7 @@ breakChars = try $ string "%%%" >> return B.linebreak
555553
556554-- superscript: foo{TAG(tag=>sup)}super{TAG}foo / bar{SUP()}super2{SUP}bar
557555superTag :: PandocMonad m => TikiWikiParser m B.Inlines
558−superTag = try $ between (string "{TAG(tag=>sup)}") (string "{TAG}") nestedString >>= return . B.superscript . B.text . fromEntities
556+superTag = try $ fmap (B.superscript . B.text . fromEntities) ( between (string "{TAG(tag=>sup)}") (string "{TAG}") nestedString)
559557
560558superMacro :: PandocMonad m => TikiWikiParser m B.Inlines
561559superMacro = try $ do
@@ -566,7 +564,7 @@ superMacro = try $ do
566564
567565-- subscript: baz{TAG(tag=>sub)}sub{TAG}qux / qux{SUB()}sub2{SUB}qux
568566subTag :: PandocMonad m => TikiWikiParser m B.Inlines
569−subTag = try $ between (string "{TAG(tag=>sub)}") (string "{TAG}") nestedString >>= return . B.subscript . B.text . fromEntities
567+subTag = try $ fmap (B.subscript . B.text . fromEntities) ( between (string "{TAG(tag=>sub)}") (string "{TAG}") nestedString)
570568
571569subMacro :: PandocMonad m => TikiWikiParser m B.Inlines
572570subMacro = try $ do
@@ -577,7 +575,7 @@ subMacro = try $ do
577575
578576-- -+text+-
579577code :: PandocMonad m => TikiWikiParser m B.Inlines
580−code = try $ between (string "-+") (string "+-") nestedString >>= return . B.code . fromEntities
578+code = try $ fmap (B.code . fromEntities) ( between (string "-+") (string "+-") nestedString)
581579
582580macroAttr :: PandocMonad m => TikiWikiParser m (String, String)
583581macroAttr = try $ do
@@ -590,8 +588,7 @@ macroAttr = try $ do
590588
591589macroAttrs :: PandocMonad m => TikiWikiParser m [(String, String)]
592590macroAttrs = try $ do
593− attrs <- sepEndBy macroAttr spaces
594− return attrs
591+ sepEndBy macroAttr spaces
595592
596593-- ~np~ __not bold__ ~/np~
597594noparse :: PandocMonad m => TikiWikiParser m B.Inlines
@@ -601,10 +598,10 @@ noparse = try $ do
601598 return $ B.str body
602599
603600str :: PandocMonad m => TikiWikiParser m B.Inlines
604−str = (many1 alphaNum <|> count 1 characterReference) >>= return . B.str
601+str = fmap B.str (many1 alphaNum <|> count 1 characterReference)
605602
606603symbol :: PandocMonad m => TikiWikiParser m B.Inlines
607−symbol = count 1 nonspaceChar >>= return . B.str
604+symbol = fmap B.str (count 1 nonspaceChar)
608605
609606-- [[not a link]
610607notExternalLink :: PandocMonad m => TikiWikiParser m B.Inlines
@@ -627,7 +624,7 @@ makeLink start middle end = try $ do
627624 (url, title, anchor) <- wikiLinkText start middle end
628625 parsedTitle <- parseFromString (many1 inline) title
629626 setState $ st{ stateAllowLinks = True }
630− return $ B.link (url++anchor) "" $ mconcat $ parsedTitle
627+ return $ B.link (url++anchor) "" $mconcat parsedTitle
631628
632629wikiLinkText :: PandocMonad m => String -> String -> String -> TikiWikiParser m (String, String, String)
633630wikiLinkText start middle end = do
@@ -643,9 +640,9 @@ wikiLinkText start middle end = do
643640 return (url, seg1, "")
644641 where
645642 linkContent = do
646− (char '|')
643+ char '|'
647644 mystr <- many (noneOf middle)
648− return $ mystr
645+ return mystr
649646
650647externalLink :: PandocMonad m => TikiWikiParser m B.Inlines
651648externalLink = makeLink "[" "]|" "]"
@@ -657,4 +654,3 @@ externalLink = makeLink "[" "]|" "]"
657654-- [see also this other post](My Other Page) is perfectly valid.
658655wikiLink :: PandocMonad m => TikiWikiParser m B.Inlines
659656wikiLink = makeLink "((" ")|" "))"
660−
src/Text/Pandoc/Readers/Vimwiki.hs+64−65
@@ -91,14 +91,13 @@ import Text.Pandoc.Parsing (F, ParserState, ParserT, blanklines, emailAddress,
9191 registerHeader, runF, spaceChar, stateMeta',
9292 stateOptions, uri)
9393import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast)
94−import Text.Parsec.Char (alphaNum, anyChar, char, newline, noneOf, spaces,
95− string)
96−import Text.Parsec.Char (oneOf, space)
97−import Text.Parsec.Combinator (choice, count, eof, many1, manyTill,
98− notFollowedBy, option, skipMany1)
99−import Text.Parsec.Combinator (between, lookAhead)
100−import Text.Parsec.Prim (getState, many, try, updateState)
101−import Text.Parsec.Prim ((<|>))
94+import Text.Parsec.Char
95+ (alphaNum, anyChar, char, newline, noneOf, spaces, string, oneOf,
96+ space)
97+import Text.Parsec.Combinator
98+ (choice, count, eof, many1, manyTill, notFollowedBy, option,
99+ skipMany1, between, lookAhead)
100+import Text.Parsec.Prim (getState, many, try, updateState, (<|>))
102101
103102readVimwiki :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
104103readVimwiki opts s = do
@@ -161,9 +160,9 @@ header = try $ do
161160 let lev = length eqs
162161 guard $ lev <= 6
163162 contents <- trimInlines . mconcat <$> manyTill inline (try $ spaceChar
164− >> (string eqs) >> many spaceChar >> newline)
163+ >> string eqs >> many spaceChar >> newline)
165164 attr <- registerHeader (makeId contents,
166− (if sp == "" then [] else ["justcenter"]), []) contents
165+ if sp == "" then [] else ["justcenter"], []) contents
167166 return $ B.headerWith attr lev contents
168167
169168para :: PandocMonad m => VwParser m Blocks
@@ -191,22 +190,22 @@ blockQuote = try $ do
191190
192191definitionList :: PandocMonad m => VwParser m Blocks
193192definitionList = try $
194− B.definitionList <$> (many1 (dlItemWithDT <|> dlItemWithoutDT))
193+ B.definitionList <$> many1 (dlItemWithDT <|> dlItemWithoutDT)
195194
196195dlItemWithDT :: PandocMonad m => VwParser m (Inlines, [Blocks])
197196dlItemWithDT = do
198197 dt <- definitionTerm
199198 dds <- many definitionDef
200− return $ (dt, dds)
199+ return (dt, dds)
201200
202201dlItemWithoutDT :: PandocMonad m => VwParser m (Inlines, [Blocks])
203202dlItemWithoutDT = do
204203 dds <- many1 definitionDef
205− return $ (mempty, dds)
204+ return (mempty, dds)
206205
207206definitionDef :: PandocMonad m => VwParser m Blocks
208207definitionDef = try $
209− (notFollowedBy definitionTerm) >> many spaceChar
208+ notFollowedBy definitionTerm >> many spaceChar
210209 >> (definitionDef1 <|> definitionDef2)
211210
212211definitionDef1 :: PandocMonad m => VwParser m Blocks
@@ -220,16 +219,16 @@ definitionDef2 = try $ B.plain <$>
220219definitionTerm :: PandocMonad m => VwParser m Inlines
221220definitionTerm = try $ do
222221 x <- definitionTerm1 <|> definitionTerm2
223− guard $ (stringify x /= "")
222+ guard (stringify x /= "")
224223 return x
225224
226225definitionTerm1 :: PandocMonad m => VwParser m Inlines
227226definitionTerm1 = try $
228− trimInlines . mconcat <$> manyTill inline' (try $ defMarkerE)
227+ trimInlines . mconcat <$> manyTill inline' (try defMarkerE)
229228
230229definitionTerm2 :: PandocMonad m => VwParser m Inlines
231230definitionTerm2 = try $ trimInlines . mconcat <$> manyTill inline'
232− (try $ lookAhead $ (defMarkerM >> notFollowedBy hasDefMarkerM))
231+ (try $lookAhead (defMarkerM >> notFollowedBy hasDefMarkerM))
233232
234233defMarkerM :: PandocMonad m => VwParser m Char
235234defMarkerM = string "::" >> spaceChar
@@ -247,14 +246,14 @@ preformatted = try $ do
247246 lookAhead newline
248247 contents <- manyTill anyChar (try (char '\n' >> many spaceChar >> string "}}}"
249248 >> many spaceChar >> newline))
250− if (not $ contents == "") && (head contents == '\n')
249+ if not (contents == "") && (head contents == '\n')
251250 then return $ B.codeBlockWith (makeAttr attrText) (tail contents)
252251 else return $ B.codeBlockWith (makeAttr attrText) contents
253252
254253makeAttr :: String -> Attr
255254makeAttr s =
256255 let xs = splitBy (`elem` " \t") s in
257− ("", [], catMaybes $ map nameValue xs)
256+ ("", [], mapMaybe nameValue xs)
258257
259258nameValue :: String -> Maybe (String, String)
260259nameValue s =
@@ -262,7 +261,7 @@ nameValue s =
262261 if length t /= 2
263262 then Nothing
264263 else let (a, b) = (head t, last t) in
265− if ((length b) < 2) || ((head b, last b) /= ('"', '"'))
264+ if (length b < 2) || ((head b, last b) /= ('"', '"'))
266265 then Nothing
267266 else Just (a, stripFirstAndLast b)
268267
@@ -317,12 +316,12 @@ mixedList' prevInd = do
317316 if lowInd >= curInd
318317 then do
319318 (sameIndList, endInd) <- (mixedList' lowInd)
320− let curList = (combineList curLine subList) ++ sameIndList
319+ let curList = combineList curLine subList ++ sameIndList
321320 if curInd > prevInd
322321 then return ([listBuilder curList], endInd)
323322 else return (curList, endInd)
324323 else do
325− let (curList, endInd) = ((combineList curLine subList),
324+ let (curList, endInd) = (combineList curLine subList,
326325 lowInd)
327326 if curInd > prevInd
328327 then return ([listBuilder curList], endInd)
@@ -335,7 +334,7 @@ plainInlineML' w = do
335334 return $ B.plain $ trimInlines $ mconcat $ w:xs
336335
337336plainInlineML :: PandocMonad m => VwParser m Blocks
338−plainInlineML = (notFollowedBy listStart) >> spaceChar >> plainInlineML' mempty
337+plainInlineML = notFollowedBy listStart >> spaceChar >> plainInlineML' mempty
339338
340339
341340listItemContent :: PandocMonad m => VwParser m Blocks
@@ -372,9 +371,9 @@ makeListMarkerSpan x =
372371
373372combineList :: Blocks -> [Blocks] -> [Blocks]
374373combineList x [y] = case toList y of
375− [BulletList z] -> [fromList $ (toList x)
374+ [BulletList z] -> [fromList $ toList x
376375 ++ [BulletList z]]
377− [OrderedList attr z] -> [fromList $ (toList x)
376+ [OrderedList attr z] -> [fromList $ toList x
378377 ++ [OrderedList attr z]]
379378 _ -> x:[y]
380379combineList x xs = x:xs
@@ -391,7 +390,7 @@ bulletListMarkers = "ul" <$ (char '*' <|> char '-')
391390
392391orderedListMarkers :: PandocMonad m => VwParser m String
393392orderedListMarkers =
394− ("ol" <$ (choice $ (orderedListMarker Decimal Period):(($OneParen)
393+ ("ol" <$choice ((orderedListMarker Decimal Period):(($OneParen)
395394 <$> orderedListMarker
396395 <$> [Decimal, LowerRoman, UpperRoman, LowerAlpha, UpperAlpha])))
397396 <|> ("ol" <$ char '#')
@@ -418,11 +417,11 @@ table1 = try $ do
418417table2 :: PandocMonad m => VwParser m ([Blocks], [[Blocks]])
419418table2 = try $ do
420419 trs <- many1 tableRow
421− return (take (length $ head trs) $ repeat mempty, trs)
420+ return (replicate (length $ head trs) mempty, trs)
422421
423422tableHeaderSeparator :: PandocMonad m => VwParser m ()
424423tableHeaderSeparator = try $ do
425− many spaceChar >> char '|' >> many1 ((many1 $ char '-') >> char '|')
424+ many spaceChar >> char '|' >> many1 (many1 (char '-') >> char '|')
426425 >> many spaceChar >> newline
427426 return ()
428427
@@ -438,16 +437,16 @@ tableRow = try $ do
438437
439438tableCell :: PandocMonad m => VwParser m Blocks
440439tableCell = try $
441− B.plain <$> trimInlines . mconcat <$> (manyTill inline' (char '|'))
440+ B.plain . trimInlines . mconcat <$> (manyTill inline' (char '|'))
442441
443442placeholder :: PandocMonad m => VwParser m ()
444443placeholder = try $
445− (choice (ph <$> ["title", "date"])) <|> noHtmlPh <|> templatePh
444+ choice (ph <$> ["title", "date"]) <|> noHtmlPh <|> templatePh
446445
447446ph :: PandocMonad m => String -> VwParser m ()
448447ph s = try $ do
449− many spaceChar >> (string $ '%':s) >> spaceChar
450− contents <- (trimInlines . mconcat <$> (manyTill inline (lookAhead newline)))
448+ many spaceChar >>string ('%':s) >> spaceChar
449+ contents <- trimInlines . mconcat <$> (manyTill inline (lookAhead newline))
451450 --use lookAhead because of placeholder in the whitespace parser
452451 let meta' = return $ B.setMeta s contents nullMeta :: F Meta
453452 updateState $ \st -> st { stateMeta' = stateMeta' st <> meta' }
@@ -455,17 +454,17 @@ ph s = try $ do
455454noHtmlPh :: PandocMonad m => VwParser m ()
456455noHtmlPh = try $
457456 () <$ (many spaceChar >> string "%nohtml" >> many spaceChar
458− >> (lookAhead newline))
457+ >> lookAhead newline)
459458
460459templatePh :: PandocMonad m => VwParser m ()
461460templatePh = try $
462− () <$ (many spaceChar >> string "%template" >> (many $ noneOf "\n")
463− >> (lookAhead newline))
461+ () <$ (many spaceChar >> string "%template" >>many (noneOf "\n")
462+ >> lookAhead newline)
464463
465464-- inline parser
466465
467466inline :: PandocMonad m => VwParser m Inlines
468−inline = choice $ (whitespace endlineP):inlineList
467+inline = choice $ whitespace endlineP:inlineList
469468
470469inlineList :: PandocMonad m => [VwParser m Inlines]
471470inlineList = [ bareURL
@@ -490,18 +489,18 @@ inline' = choice $ whitespace':inlineList
490489
491490-- inline parser for blockquotes
492491inlineBQ :: PandocMonad m => VwParser m Inlines
493−inlineBQ = choice $ (whitespace endlineBQ):inlineList
492+inlineBQ = choice $ whitespace endlineBQ:inlineList
494493
495494-- inline parser for mixedlists
496495inlineML :: PandocMonad m => VwParser m Inlines
497−inlineML = choice $ (whitespace endlineML):inlineList
496+inlineML = choice $ whitespace endlineML:inlineList
498497
499498str :: PandocMonad m => VwParser m Inlines
500−str = B.str <$> (many1 $ noneOf $ spaceChars ++ specialChars)
499+str = B.str <$>many1 (noneOf $ spaceChars ++ specialChars)
501500
502501whitespace :: PandocMonad m => VwParser m () -> VwParser m Inlines
503502whitespace endline = B.space <$ (skipMany1 spaceChar <|>
504− (try (newline >> (comment <|> placeholder))))
503+ try (newline >> (comment <|> placeholder)))
505504 <|> B.softbreak <$ endline
506505
507506whitespace' :: PandocMonad m => VwParser m Inlines
@@ -518,31 +517,31 @@ bareURL = try $ do
518517strong :: PandocMonad m => VwParser m Inlines
519518strong = try $ do
520519 s <- lookAhead $ between (char '*') (char '*') (many1 $ noneOf "*")
521− guard $ (not $ (head s) `elem` spaceChars)
522− && (not $ (last s) `elem` spaceChars)
520+ guard $ not ((head s) `elem` spaceChars)
521+ &&not ((last s) `elem` spaceChars)
523522 char '*'
524− contents <- mconcat <$> (manyTill inline' $ char '*'
523+ contents <- mconcat <$>manyTill inline' (char '*'
525524 >> notFollowedBy alphaNum)
526− return $ (B.spanWith ((makeId contents), [], []) mempty)
527− <> (B.strong contents)
525+ return $ B.spanWith ((makeId contents), [], []) mempty
526+ <> B.strong contents
528527
529528makeId :: Inlines -> String
530−makeId i = concat (stringify <$> (toList i))
529+makeId i = concat (stringify <$> toList i)
531530
532531emph :: PandocMonad m => VwParser m Inlines
533532emph = try $ do
534533 s <- lookAhead $ between (char '_') (char '_') (many1 $ noneOf "_")
535− guard $ (not $ (head s) `elem` spaceChars)
536− && (not $ (last s) `elem` spaceChars)
534+ guard $ not ((head s) `elem` spaceChars)
535+ &&not ((last s) `elem` spaceChars)
537536 char '_'
538− contents <- mconcat <$> (manyTill inline' $ char '_'
537+ contents <- mconcat <$>manyTill inline' (char '_'
539538 >> notFollowedBy alphaNum)
540539 return $ B.emph contents
541540
542541strikeout :: PandocMonad m => VwParser m Inlines
543542strikeout = try $ do
544543 string "~~"
545− contents <- mconcat <$> (many1Till inline' $ string $ "~~")
544+ contents <- mconcat <$>many1Till inline' (string $ "~~")
546545 return $ B.strikeout contents
547546
548547code :: PandocMonad m => VwParser m Inlines
@@ -553,11 +552,11 @@ code = try $ do
553552
554553superscript :: PandocMonad m => VwParser m Inlines
555554superscript = try $
556− B.superscript <$> mconcat <$> (char '^' >> many1Till inline' (char '^'))
555+ B.superscript . mconcat <$> (char '^' >> many1Till inline' (char '^'))
557556
558557subscript :: PandocMonad m => VwParser m Inlines
559558subscript = try $
560− B.subscript <$> mconcat <$> (string ",,"
559+ B.subscript . mconcat <$> (string ",,"
561560 >> many1Till inline' (try $ string ",,"))
562561
563562link :: PandocMonad m => VwParser m Inlines
@@ -587,29 +586,29 @@ images k
587586 return $ B.image (procImgurl imgurl) "" (B.str "")
588587 | k == 1 = do
589588 imgurl <- manyTill anyChar (char '|')
590− alt <- mconcat <$> (manyTill inline $ (try $ string "}}"))
589+ alt <- mconcat <$> (manyTill inline (try $ string "}}"))
591590 return $ B.image (procImgurl imgurl) "" alt
592591 | k == 2 = do
593592 imgurl <- manyTill anyChar (char '|')
594− alt <- mconcat <$> (manyTill inline $ char '|')
593+ alt <- mconcat <$>manyTill inline (char '|')
595594 attrText <- manyTill anyChar (try $ string "}}")
596595 return $ B.imageWith (makeAttr attrText) (procImgurl imgurl) "" alt
597596 | otherwise = do
598597 imgurl <- manyTill anyChar (char '|')
599− alt <- mconcat <$> (manyTill inline $ char '|')
598+ alt <- mconcat <$>manyTill inline (char '|')
600599 attrText <- manyTill anyChar (char '|')
601600 manyTill anyChar (try $ string "}}")
602601 return $ B.imageWith (makeAttr attrText) (procImgurl imgurl) "" alt
603602
604603procLink' :: String -> String
605604procLink' s
606− | ((take 6 s) == "local:") = "file" ++ (drop 5 s)
607− | ((take 6 s) == "diary:") = "diary/" ++ (drop 6 s) ++ ".html"
605+ | (take 6 s) == "local:" = "file" ++ drop 5 s
606+ | (take 6 s) == "diary:" = "diary/" ++ drop 6 s ++ ".html"
608607 | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
609608 "news:", "telnet:" ])
610609 = s
611610 | s == "" = ""
612− | (last s) == '/' = s
611+ | last s == '/' = s
613612 | otherwise = s ++ ".html"
614613
615614procLink :: String -> String
@@ -617,7 +616,7 @@ procLink s = procLink' x ++ y
617616 where (x, y) = break (=='#') s
618617
619618procImgurl :: String -> String
620−procImgurl s = if ((take 6 s) == "local:") then "file" ++ (drop 5 s) else s
619+procImgurl s = if (take 6 s) == "local:" then "file" ++ drop 5 s else s
621620
622621inlineMath :: PandocMonad m => VwParser m Inlines
623622inlineMath = try $ do
@@ -628,10 +627,10 @@ inlineMath = try $ do
628627tag :: PandocMonad m => VwParser m Inlines
629628tag = try $ do
630629 char ':'
631− s <- manyTill (noneOf spaceChars) (try (char ':' >> (lookAhead space)))
630+ s <- manyTill (noneOf spaceChars) (try (char ':' >> lookAhead space))
632631 guard $ not $ "::" `isInfixOf` (":" ++ s ++ ":")
633632 let ss = splitBy (==':') s
634− return $ mconcat $ (makeTagSpan' $ head ss):(makeTagSpan <$> (tail ss))
633+ return $ mconcat $ makeTagSpan' (head ss):(makeTagSpan <$> tail ss)
635634
636635todoMark :: PandocMonad m => VwParser m Inlines
637636todoMark = try $ do
@@ -661,18 +660,18 @@ nFBTTBSB =
661660 notFollowedBy hasDefMarker
662661
663662hasDefMarker :: PandocMonad m => VwParser m ()
664−hasDefMarker = () <$ (manyTill (noneOf "\n") (string "::" >> oneOf spaceChars))
663+hasDefMarker = () <$ manyTill (noneOf "\n") (string "::" >> oneOf spaceChars)
665664
666665makeTagSpan' :: String -> Inlines
667666makeTagSpan' s = B.spanWith ('-' : s, [], []) (B.str "") <>
668667 B.spanWith (s, ["tag"], []) (B.str s)
669668
670669makeTagSpan :: String -> Inlines
671−makeTagSpan s = (B.space) <> (makeTagSpan' s)
670+makeTagSpan s = B.space <> makeTagSpan' s
672671
673672mathTagParser :: PandocMonad m => VwParser m String
674673mathTagParser = do
675− s <- try $ lookAhead (char '%' >> (manyTill (noneOf spaceChars)
676− (try $ char '%' >> many (noneOf $ '%':spaceChars) >> space)))
674+ s <- try $ lookAhead (char '%' >> manyTill (noneOf spaceChars)
675+ (try $ char '%' >> many (noneOf $ '%':spaceChars) >> space))
677676 char '%' >> string s >> char '%'
678677 return $ mathTagLaTeX s
src/Text/Pandoc/SelfContained.hs+5−8
@@ -178,10 +178,10 @@ pCSSComment = P.try $ do
178178 return B.empty
179179
180180pCSSOther :: PandocMonad m => ParsecT ByteString () m ByteString
181−pCSSOther = do
181+pCSSOther =
182182 (B.pack <$> P.many1 (P.noneOf "u/ \n\r\t")) <|>
183− (B.singleton <$> P.char 'u') <|>
184− (B.singleton <$> P.char '/')
183+ (B.singleton <$> P.char 'u') <|>
184+ (B.singleton <$> P.char '/')
185185
186186pCSSUrl :: PandocMonad m
187187 => FilePath -> ParsecT ByteString () m ByteString
@@ -218,9 +218,7 @@ handleCSSUrl :: PandocMonad m
218218 => FilePath -> (String, ByteString)
219219 -> ParsecT ByteString () m
220220 (Either ByteString (MimeType, ByteString))
221−handleCSSUrl d (url, fallback) = do
222− -- pipes are used in URLs provided by Google Code fonts
223− -- but parseURI doesn't like them, so we escape them:
221+handleCSSUrl d (url, fallback) =
224222 case escapeURIString (/='|') (trim url) of
225223 '#':_ -> return $ Left fallback
226224 'd':'a':'t':'a':':':_ -> return $ Left fallback
@@ -251,8 +249,7 @@ getData mimetype src = do
251249 let ext = map toLower $ takeExtension src
252250 (raw, respMime) <- fetchItem src
253251 let raw' = if ext == ".gz"
254− then B.concat $ L.toChunks $ Gzip.decompress $ L.fromChunks
255− $ [raw]
252+ then B.concat $ L.toChunks $ Gzip.decompress $ L.fromChunks [raw]
256253 else raw
257254 mime <- case (mimetype, respMime) of
258255 ("",Nothing) -> throwError $ PandocSomeError
src/Text/Pandoc/Shared.hs+21−22
@@ -2,7 +2,7 @@
22{-# LANGUAGE DeriveDataTypeable #-}
33{-# LANGUAGE FlexibleContexts #-}
44{-# LANGUAGE MultiParamTypeClasses #-}
5−{-# LANGUAGE PatternGuards #-}
5+
66{-# LANGUAGE ScopedTypeVariables #-}
77{-# LANGUAGE ViewPatterns #-}
88{-
@@ -144,11 +144,11 @@ splitBy _ [] = []
144144splitBy isSep lst =
145145 let (first, rest) = break isSep lst
146146 rest' = dropWhile isSep rest
147− in first:(splitBy isSep rest')
147+ in first:splitBy isSep rest'
148148
149149splitByIndices :: [Int] -> [a] -> [[a]]
150150splitByIndices [] lst = [lst]
151−splitByIndices (x:xs) lst = first:(splitByIndices (map (\y -> y - x) xs) rest)
151+splitByIndices (x:xs) lst = first:splitByIndices (map (\y -> y - x) xs) rest
152152 where (first, rest) = splitAt x lst
153153
154154-- | Split string into chunks divided at specified indices.
@@ -156,7 +156,7 @@ splitStringByIndices :: [Int] -> [Char] -> [[Char]]
156156splitStringByIndices [] lst = [lst]
157157splitStringByIndices (x:xs) lst =
158158 let (first, rest) = splitAt' x lst in
159− first : (splitStringByIndices (map (\y -> y - x) xs) rest)
159+ first : splitStringByIndices (map (\y -> y - x) xs) rest
160160
161161splitAt' :: Int -> [Char] -> ([Char],[Char])
162162splitAt' _ [] = ([],[])
@@ -195,7 +195,7 @@ backslashEscapes = map (\ch -> (ch, ['\\',ch]))
195195escapeStringUsing :: [(Char, String)] -> String -> String
196196escapeStringUsing _ [] = ""
197197escapeStringUsing escapeTable (x:xs) =
198− case (lookup x escapeTable) of
198+ case lookup x escapeTable of
199199 Just str -> str ++ rest
200200 Nothing -> x:rest
201201 where rest = escapeStringUsing escapeTable xs
@@ -219,14 +219,14 @@ trimr = reverse . triml . reverse
219219-- | Strip leading and trailing characters from string
220220stripFirstAndLast :: String -> String
221221stripFirstAndLast str =
222− drop 1 $ take ((length str) - 1) str
222+ drop 1 $ take (length str - 1) str
223223
224224-- | Change CamelCase word to hyphenated lowercase (e.g., camel-case).
225225camelCaseToHyphenated :: String -> String
226226camelCaseToHyphenated [] = ""
227227camelCaseToHyphenated (a:b:rest) | isLower a && isUpper b =
228− a:'-':(toLower b):(camelCaseToHyphenated rest)
229−camelCaseToHyphenated (a:rest) = (toLower a):(camelCaseToHyphenated rest)
228+ a:'-':toLower b:camelCaseToHyphenated rest
229+camelCaseToHyphenated (a:rest) = toLower a:camelCaseToHyphenated rest
230230
231231-- | Convert number < 4000 to uppercase roman numeral.
232232toRomanNumeral :: Int -> String
@@ -477,7 +477,7 @@ hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) []
477477
478478hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element]
479479hierarchicalizeWithIds [] = return []
480−hierarchicalizeWithIds ((Header level attr@(_,classes,_) title'):xs) = do
480+hierarchicalizeWithIds (Header level attr@(_,classes,_) title':xs) = do
481481 lastnum <- S.get
482482 let lastnum' = take level lastnum
483483 let newnum = case length lastnum' of
@@ -490,13 +490,13 @@ hierarchicalizeWithIds ((Header level attr@(_,classes,_) title'):xs) = do
490490 sectionContents' <- hierarchicalizeWithIds sectionContents
491491 rest' <- hierarchicalizeWithIds rest
492492 return $ Sec level newnum attr title' sectionContents' : rest'
493−hierarchicalizeWithIds ((Div ("",["references"],[])
494− (Header level (ident,classes,kvs) title' : xs)):ys) =
495− hierarchicalizeWithIds ((Header level (ident,("references":classes),kvs)
496− title') : (xs ++ ys))
493+hierarchicalizeWithIds (Div ("",["references"],[])
494+ (Header level (ident,classes,kvs) title' : xs):ys) =
495+ hierarchicalizeWithIds (Header level (ident,("references":classes),kvs)
496+ title' : (xs ++ ys))
497497hierarchicalizeWithIds (x:rest) = do
498498 rest' <- hierarchicalizeWithIds rest
499− return $ (Blk x) : rest'
499+ return $ Blk x : rest'
500500
501501headerLtEq :: Int -> Block -> Bool
502502headerLtEq level (Header l _ _) = l <= level
@@ -519,7 +519,7 @@ uniqueIdent title' usedIdents
519519
520520-- | True if block is a Header block.
521521isHeaderBlock :: Block -> Bool
522−isHeaderBlock (Header _ _ _) = True
522+isHeaderBlock (Header{}) = True
523523isHeaderBlock _ = False
524524
525525-- | Shift header levels up or down.
@@ -555,15 +555,14 @@ makeMeta :: [Inline] -> [[Inline]] -> [Inline] -> Meta
555555makeMeta title authors date =
556556 addMetaField "title" (B.fromList title)
557557 $ addMetaField "author" (map B.fromList authors)
558− $ addMetaField "date" (B.fromList date)
559− $ nullMeta
558+ $ addMetaField "date" (B.fromList date) nullMeta
560559
561560-- | Remove soft breaks between East Asian characters.
562561eastAsianLineBreakFilter :: Pandoc -> Pandoc
563562eastAsianLineBreakFilter = bottomUp go
564563 where go (x:SoftBreak:y:zs) =
565564 case (stringify x, stringify y) of
566− (xs@(_:_), (c:_))
565+ (xs@(_:_), c:_)
567566 | charWidth (last xs) == 2 && charWidth c == 2 -> x:y:zs
568567 _ -> x:SoftBreak:y:zs
569568 go xs = xs
@@ -620,8 +619,8 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
620619 where
621620 go rs "." = rs
622621 go r@(p:rs) ".." = case p of
623− ".." -> ("..":r)
624− (checkPathSeperator -> Just True) -> ("..":r)
622+ ".." -> "..":r
623+ (checkPathSeperator -> Just True) -> "..":r
625624 _ -> rs
626625 go _ (checkPathSeperator -> Just True) = [[Posix.pathSeparator]]
627626 go rs x = x:rs
@@ -725,9 +724,9 @@ blockToInlines (DefinitionList pairslst) =
725724 where
726725 f (ils, blkslst) = ils ++
727726 [Str ":", Space] ++
728− (concatMap blocksToInlines blkslst)
727+ concatMap blocksToInlines blkslst
729728blockToInlines (Header _ _ ils) = ils
730−blockToInlines (HorizontalRule) = []
729+blockToInlines HorizontalRule = []
731730blockToInlines (Table _ _ _ headers rows) =
732731 intercalate [LineBreak] $ map (concatMap blocksToInlines) tbl
733732 where
src/Text/Pandoc/Slides.hs+2−2
@@ -40,8 +40,8 @@ getSlideLevel = go 6
4040 | otherwise = go least (x:xs)
4141 go least (_ : xs) = go least xs
4242 go least [] = least
43− nonHOrHR (Header{}) = False
44− nonHOrHR (HorizontalRule) = False
43+ nonHOrHR Header{} = False
44+ nonHOrHR HorizontalRule = False
4545 nonHOrHR _ = True
4646
4747-- | Prepare a block list to be passed to hierarchicalize.
src/Text/Pandoc/Templates.hs+2−2
@@ -1,5 +1,5 @@
11{-# LANGUAGE FlexibleInstances #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+
33{-# LANGUAGE OverloadedStrings #-}
44{-# LANGUAGE TypeSynonymInstances #-}
55{-
@@ -77,7 +77,7 @@ getDefaultTemplate writer = do
7777-- raises an error if compilation fails.
7878renderTemplate' :: (PandocMonad m, ToJSON a, TemplateTarget b)
7979 => String -> a -> m b
80−renderTemplate' template context = do
80+renderTemplate' template context =
8181 case applyTemplate (T.pack template) context of
8282 Left e -> throwError (PandocTemplateError e)
8383 Right r -> return r
src/Text/Pandoc/UUID.hs−1
@@ -75,4 +75,3 @@ getUUID gen =
7575
7676getRandomUUID :: IO UUID
7777getRandomUUID = getUUID <$> getStdGen
78−